Guest User

Untitled

a guest
Nov 22nd, 2017
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.25 KB | None | 0 0
  1. public class RoundRobinPartitioningFailoverStrategy : INamespacePartitioningStrategy
  2. {
  3. private readonly CircularBuffer<RuntimeNamespaceInfo[]> _namespaces;
  4. public RoundRobinPartitioningFailoverStrategy(ReadOnlySettings settings)
  5. {
  6. if (!settings.TryGet("AzureServiceBus.Settings.Topology.Addressing.Namespaces",
  7. out NamespaceConfigurations namespaces))
  8. {
  9. 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.");
  10. }
  11. var partitioningNamespaces = namespaces.Where(x => x.Purpose == NamespacePurpose.Partitioning).ToList();
  12. if (partitioningNamespaces.Count != 2)
  13. {
  14. 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.");
  15. }
  16. _namespaces = new CircularBuffer<RuntimeNamespaceInfo[]>(partitioningNamespaces.Count);
  17. var first = namespaces.First();
  18. var second = namespaces.Last();
  19.  
  20. _namespaces.Put(new []
  21. {
  22. new RuntimeNamespaceInfo(first.Alias, first.ConnectionString, first.Purpose, NamespaceMode.Active),
  23. new RuntimeNamespaceInfo(second.Alias, second.ConnectionString, second.Purpose, NamespaceMode.Passive),
  24. });
  25. _namespaces.Put(new []
  26. {
  27. new RuntimeNamespaceInfo(first.Alias, first.ConnectionString, first.Purpose, NamespaceMode.Passive),
  28. new RuntimeNamespaceInfo(second.Alias, second.ConnectionString, second.Purpose, NamespaceMode.Active),
  29. });
  30. }
  31. public IEnumerable<RuntimeNamespaceInfo> GetNamespaces(PartitioningIntent partitioningIntent)
  32. {
  33. return _namespaces.Get();
  34. }
  35. }
Add Comment
Please, Sign In to add comment