Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class RoundRobinPartitioningFailoverStrategy : INamespacePartitioningStrategy
- {
- private readonly CircularBuffer<RuntimeNamespaceInfo[]> _namespaces;
- public RoundRobinPartitioningFailoverStrategy(ReadOnlySettings settings)
- {
- if (!settings.TryGet("AzureServiceBus.Settings.Topology.Addressing.Namespaces",
- out NamespaceConfigurations namespaces))
- {
- throw new ConfigurationErrorsException($"The '{nameof(RoundRobinPartitioningFailoverStrategy)}' strategy requires exactly two namespaces to be configured, please use {nameof(AzureServiceBusTransportExtensions.NamespacePartitioning)}().{nameof(AzureServiceBusNamespacePartitioningSettings.AddNamespace)}() to register the namespaces.");
- }
- var partitioningNamespaces = namespaces.Where(x => x.Purpose == NamespacePurpose.Partitioning).ToList();
- if (partitioningNamespaces.Count != 2)
- {
- throw new ConfigurationErrorsException($"The '{nameof(RoundRobinPartitioningFailoverStrategy)}' strategy requires exactly two namespaces to be configured, please use {nameof(AzureServiceBusTransportExtensions.NamespacePartitioning)}().{nameof(AzureServiceBusNamespacePartitioningSettings.AddNamespace)}() to register the namespaces.");
- }
- _namespaces = new CircularBuffer<RuntimeNamespaceInfo[]>(partitioningNamespaces.Count);
- var first = namespaces.First();
- var second = namespaces.Last();
- _namespaces.Put(new []
- {
- new RuntimeNamespaceInfo(first.Alias, first.ConnectionString, first.Purpose, NamespaceMode.Active),
- new RuntimeNamespaceInfo(second.Alias, second.ConnectionString, second.Purpose, NamespaceMode.Passive),
- });
- _namespaces.Put(new []
- {
- new RuntimeNamespaceInfo(first.Alias, first.ConnectionString, first.Purpose, NamespaceMode.Passive),
- new RuntimeNamespaceInfo(second.Alias, second.ConnectionString, second.Purpose, NamespaceMode.Active),
- });
- }
- public IEnumerable<RuntimeNamespaceInfo> GetNamespaces(PartitioningIntent partitioningIntent)
- {
- return _namespaces.Get();
- }
- }
Add Comment
Please, Sign In to add comment