Skip to content

Commit 1fb4c54

Browse files
danielmarbachmauroservientipoornimanayar
authored
Add support for Azure Service Bus entities partitioning (#3959) (#3961)
Co-authored-by: Mauro Servienti <[email protected]> Co-authored-by: Poornima Nayar <[email protected]>
1 parent c52eaa1 commit 1fb4c54

File tree

5 files changed

+28
-5
lines changed

5 files changed

+28
-5
lines changed

src/ServiceControl.Transports.ASBS.Tests/ConnectionStringParserTests.cs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,9 @@ public static IEnumerable<TestCaseData> SupportedConnectionStrings
3434
//Custom query delay interval
3535
yield return new TestCaseData("Endpoint=sb://some.endpoint.name/;QueueLengthQueryDelayInterval=15000",
3636
new ConnectionSettings(new SharedAccessSignatureAuthentication("Endpoint=sb://some.endpoint.name/;QueueLengthQueryDelayInterval=15000"), queryDelayInterval: TimeSpan.FromSeconds(15)));
37+
//EnablePartitioning
38+
yield return new TestCaseData("Endpoint=sb://some.endpoint.name/;EnablePartitioning=True",
39+
new ConnectionSettings(new SharedAccessSignatureAuthentication("Endpoint=sb://some.endpoint.name/;EnablePartitioning=True"), enablePartitioning: true));
3740
}
3841
}
3942

@@ -61,13 +64,13 @@ public void VerifySupported(string connectionString, ConnectionSettings expected
6164

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

64-
//needed since System..Text.Json doesn't handle polymorphic properties
67+
//needed since System.Text.Json doesn't handle polymorphic properties
6568
Assert.AreEqual(
6669
JsonSerializer.Serialize(expected.AuthenticationMethod, expected.AuthenticationMethod.GetType()),
6770
JsonSerializer.Serialize(actual.AuthenticationMethod, actual.AuthenticationMethod.GetType()));
6871

6972

70-
//needed since System..Text.Json doesn't handle polymorphic properties
73+
//needed since System.Text.Json doesn't handle polymorphic properties
7174
if (expected.AuthenticationMethod is TokenCredentialAuthentication expectedAuthentication)
7275
{
7376
var actualAuthentication = actual.AuthenticationMethod as TokenCredentialAuthentication;

src/ServiceControl.Transports.ASBS/ASBSTransportCustomization.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,11 @@ void CustomizeEndpoint(
6969
transport.UseWebSockets();
7070
}
7171

72+
if (connectionSettings.EnablePartitioning)
73+
{
74+
transport.EnablePartitioning();
75+
}
76+
7277
transport.ConfigureNameShorteners();
7378
transport.Transactions(transportTransactionMode);
7479

src/ServiceControl.Transports.ASBS/ConnectionSettings.cs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,16 @@
44

55
public class ConnectionSettings
66
{
7-
public ConnectionSettings(
8-
AuthenticationMethod authenticationSettings,
7+
public ConnectionSettings(AuthenticationMethod authenticationSettings,
98
string topicName = default,
109
bool useWebSockets = default,
10+
bool enablePartitioning = default,
1111
TimeSpan? queryDelayInterval = default)
1212
{
1313
AuthenticationMethod = authenticationSettings;
1414
TopicName = topicName;
1515
UseWebSockets = useWebSockets;
16+
EnablePartitioning = enablePartitioning;
1617
QueryDelayInterval = queryDelayInterval;
1718
}
1819

@@ -23,5 +24,7 @@ public ConnectionSettings(
2324
public string TopicName { get; }
2425

2526
public bool UseWebSockets { get; }
27+
28+
public bool EnablePartitioning { get; }
2629
}
2730
}

src/ServiceControl.Transports.ASBS/ConnectionStringParser.cs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,16 @@ public static ConnectionSettings Parse(string connectionString)
6262
clientIdString = (string)clientId;
6363
}
6464

65+
var enablePartitioning = false;
66+
if (builder.TryGetValue("EnablePartitioning", out var enablePartitioningString))
67+
{
68+
if (!bool.TryParse((string)enablePartitioningString, out enablePartitioning))
69+
{
70+
throw new Exception(
71+
$"Cannot enable partitioning, the specified value '{enablePartitioningString}' cannot be converted to a bool.");
72+
}
73+
}
74+
6575
var shouldUseManagedIdentity = builder.TryGetValue("Authentication", out var authType) && (string)authType == "Managed Identity";
6676

6777
if (shouldUseManagedIdentity)
@@ -72,6 +82,7 @@ public static ConnectionSettings Parse(string connectionString)
7282
new TokenCredentialAuthentication(fullyQualifiedNamespace, clientIdString),
7383
topicNameString,
7484
useWebSockets,
85+
enablePartitioning,
7586
queryDelayInterval);
7687
}
7788

@@ -84,6 +95,7 @@ public static ConnectionSettings Parse(string connectionString)
8495
new SharedAccessSignatureAuthentication(connectionString),
8596
topicNameString,
8697
useWebSockets,
98+
enablePartitioning,
8799
queryDelayInterval);
88100
}
89101
}

src/ServiceControlInstaller.Engine/Instances/ServiceControlCoreTransports.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ public class ServiceControlCoreTransports
3131
Name = TransportNames.AzureServiceBus,
3232
TypeName = "ServiceControl.Transports.ASBS.ASBSTransportCustomization, ServiceControl.Transports.ASBS",
3333
ZipName = "NetStandardAzureServiceBus",
34-
SampleConnectionString = "Endpoint=sb://[namespace].servicebus.windows.net; SharedSecretIssuer=<owner>;SharedSecretValue=<someSecret>;QueueLengthQueryDelayInterval=<IntervalInMilliseconds(Default=500ms)>;TopicName=<TopicBundleName(Default=bundle-1)>",
34+
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)>",
3535
AvailableInSCMU = true,
3636
Matches = name => name.Equals(TransportNames.AzureServiceBus, StringComparison.OrdinalIgnoreCase)
3737
|| name.Equals("ServiceControl.Transports.ASBS.ASBSTransportCustomization, ServiceControl.Transports.ASBS", StringComparison.OrdinalIgnoreCase)

0 commit comments

Comments
 (0)