Skip to content

Commit

Permalink
Add support for Azure Service Bus entities partitioning (#3959)
Browse files Browse the repository at this point in the history
Co-authored-by: Poornima Nayar <poornimakrishnav@gmail.com>
Co-authored-by: Daniel Marbach <daniel.marbach@openplace.net>
  • Loading branch information
3 people committed Feb 14, 2024
1 parent 47b3232 commit 6b03107
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 5 deletions.
Expand Up @@ -34,6 +34,9 @@ public static IEnumerable<TestCaseData> SupportedConnectionStrings
//Custom query delay interval
yield return new TestCaseData("Endpoint=sb://some.endpoint.name/;QueueLengthQueryDelayInterval=15000",
new ConnectionSettings(new SharedAccessSignatureAuthentication("Endpoint=sb://some.endpoint.name/;QueueLengthQueryDelayInterval=15000"), queryDelayInterval: TimeSpan.FromSeconds(15)));
//EnablePartitioning
yield return new TestCaseData("Endpoint=sb://some.endpoint.name/;EnablePartitioning=True",
new ConnectionSettings(new SharedAccessSignatureAuthentication("Endpoint=sb://some.endpoint.name/;EnablePartitioning=True"), enablePartitioning: true));
}
}

Expand Down Expand Up @@ -61,13 +64,13 @@ public void VerifySupported(string connectionString, ConnectionSettings expected

Assert.AreEqual(JsonSerializer.Serialize(expected), JsonSerializer.Serialize(actual));

//needed since System..Text.Json doesn't handle polymorphic properties
//needed since System.Text.Json doesn't handle polymorphic properties
Assert.AreEqual(
JsonSerializer.Serialize(expected.AuthenticationMethod, expected.AuthenticationMethod.GetType()),
JsonSerializer.Serialize(actual.AuthenticationMethod, actual.AuthenticationMethod.GetType()));


//needed since System..Text.Json doesn't handle polymorphic properties
//needed since System.Text.Json doesn't handle polymorphic properties
if (expected.AuthenticationMethod is TokenCredentialAuthentication expectedAuthentication)
{
var actualAuthentication = actual.AuthenticationMethod as TokenCredentialAuthentication;
Expand Down
Expand Up @@ -27,6 +27,8 @@ protected override AzureServiceBusTransport CreateTransport(TransportSettings tr
transport.Topology = TopicTopology.Single(connectionSettings.TopicName);
}

transport.EnablePartitioning = connectionSettings.EnablePartitioning;

transport.ConfigureNameShorteners();

transport.TransportTransactionMode = transport.GetSupportedTransactionModes().Contains(preferredTransactionMode) ? preferredTransactionMode : TransportTransactionMode.ReceiveOnly;
Expand Down
7 changes: 5 additions & 2 deletions src/ServiceControl.Transports.ASBS/ConnectionSettings.cs
Expand Up @@ -4,15 +4,16 @@

public class ConnectionSettings
{
public ConnectionSettings(
AuthenticationMethod authenticationSettings,
public ConnectionSettings(AuthenticationMethod authenticationSettings,
string topicName = default,
bool useWebSockets = default,
bool enablePartitioning = default,
TimeSpan? queryDelayInterval = default)
{
AuthenticationMethod = authenticationSettings;
TopicName = topicName;
UseWebSockets = useWebSockets;
EnablePartitioning = enablePartitioning;
QueryDelayInterval = queryDelayInterval;
}

Expand All @@ -23,5 +24,7 @@ public class ConnectionSettings
public string TopicName { get; }

public bool UseWebSockets { get; }

public bool EnablePartitioning { get; }
}
}
12 changes: 12 additions & 0 deletions src/ServiceControl.Transports.ASBS/ConnectionStringParser.cs
Expand Up @@ -62,6 +62,16 @@ public static ConnectionSettings Parse(string connectionString)
clientIdString = (string)clientId;
}

var enablePartitioning = false;
if (builder.TryGetValue("EnablePartitioning", out var enablePartitioningString))
{
if (!bool.TryParse((string)enablePartitioningString, out enablePartitioning))
{
throw new Exception(
$"Cannot enable partitioning, the specified value '{enablePartitioningString}' cannot be converted to a bool.");
}
}

var shouldUseManagedIdentity = builder.TryGetValue("Authentication", out var authType) && (string)authType == "Managed Identity";

if (shouldUseManagedIdentity)
Expand All @@ -72,6 +82,7 @@ public static ConnectionSettings Parse(string connectionString)
new TokenCredentialAuthentication(fullyQualifiedNamespace, clientIdString),
topicNameString,
useWebSockets,
enablePartitioning,
queryDelayInterval);
}

Expand All @@ -84,6 +95,7 @@ public static ConnectionSettings Parse(string connectionString)
new SharedAccessSignatureAuthentication(connectionString),
topicNameString,
useWebSockets,
enablePartitioning,
queryDelayInterval);
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/ServiceControl.Transports.ASBS/transport.manifest
Expand Up @@ -5,7 +5,7 @@
"Name": "NetStandardAzureServiceBus",
"DisplayName": "Azure Service Bus",
"TypeName": "ServiceControl.Transports.ASBS.ASBSTransportCustomization, ServiceControl.Transports.ASBS",
"SampleConnectionString": "Endpoint=sb://[namespace].servicebus.windows.net; SharedSecretIssuer=<owner>;SharedSecretValue=<someSecret>;QueueLengthQueryDelayInterval=<IntervalInMilliseconds(Default=500ms)>;TopicName=<TopicBundleName(Default=bundle-1)>",
"SampleConnectionString": "Endpoint=sb://[namespace].servicebus.windows.net; SharedSecretIssuer=<owner>;SharedSecretValue=<someSecret>;QueueLengthQueryDelayInterval=<IntervalInMilliseconds(Default=500ms)>;TopicName=<TopicBundleName(Default=bundle-1)>;EnablePartitioning=<true|false(Default=false)>",
"AvailableInSCMU": true,
"Aliases": [
"ServiceControl.Transports.AzureServiceBus.AzureServiceBusTransport, ServiceControl.Transports.AzureServiceBus"
Expand Down

0 comments on commit 6b03107

Please sign in to comment.