public UnicastRoutingStrategy Route(Type messageType, IDistributionPolicy distributionPolicy) { var route = unicastRoutingTable.GetRouteFor(messageType); if (route == null) { return(null); } if (route.PhysicalAddress != null) { return(new UnicastRoutingStrategy(route.PhysicalAddress)); } if (route.Instance != null) { return(new UnicastRoutingStrategy(transportAddressTranslation(route.Instance))); } var instances = endpointInstances.FindInstances(route.Endpoint).Select(e => transportAddressTranslation(e)).ToArray(); var selectedInstanceAddress = distributionPolicy.GetDistributionStrategy(route.Endpoint, DistributionStrategyScope.Send).SelectReceiver(instances); return(new UnicastRoutingStrategy(selectedInstanceAddress)); }
HashSet<string> SelectDestinationsForEachEndpoint(IDistributionPolicy distributionPolicy, IEnumerable<Subscriber> subscribers) { //Make sure we are sending only one to each transport destination. Might happen when there are multiple routing information sources. var addresses = new HashSet<string>(); var destinationsByEndpoint = subscribers .GroupBy(d => d.Endpoint, d => d); foreach (var group in destinationsByEndpoint) { if (group.Key == null) //Routing targets that do not specify endpoint name { //Send a message to each target as we have no idea which endpoint they represent foreach (var subscriber in group) { addresses.Add(subscriber.TransportAddress); } } else { var subscriber = distributionPolicy.GetDistributionStrategy(group.First().Endpoint, DistributionStrategyScope.Publish).SelectReceiver(group.Select(s => s.TransportAddress).ToArray()); addresses.Add(subscriber); } } return addresses; }
HashSet <string> SelectDestinationsForEachEndpoint(IEnumerable <UnicastRouteGroup> routeGroups) { //Make sure we are sending only one to each transport destination. Might happen when there are multiple routing information sources. var addresses = new HashSet <string>(); foreach (var group in routeGroups) { if (group.EndpointName == null) //Routing targets that do not specify endpoint name { //Send a message to each target as we have no idea which endpoint they represent foreach (var subscriber in group.Routes) { foreach (var address in ResolveRoute(subscriber)) { addresses.Add(address); } } } else { var candidates = group.Routes.SelectMany(ResolveRoute).ToArray(); var selected = distributionPolicy.GetDistributionStrategy(group.EndpointName, DistributionStrategyScope.Publish).SelectReceiver(candidates); addresses.Add(selected); } } return(addresses); }
HashSet <string> SelectDestinationsForEachEndpoint(IDistributionPolicy distributionPolicy, IEnumerable <Subscriber> subscribers) { //Make sure we are sending only one to each transport destination. Might happen when there are multiple routing information sources. var addresses = new HashSet <string>(); var destinationsByEndpoint = subscribers .GroupBy(d => d.Endpoint, d => d); foreach (var group in destinationsByEndpoint) { if (group.Key == null) //Routing targets that do not specify endpoint name { //Send a message to each target as we have no idea which endpoint they represent foreach (var subscriber in group) { addresses.Add(subscriber.TransportAddress); } } else { var subscriber = distributionPolicy.GetDistributionStrategy(group.First().Endpoint, DistributionStrategyScope.Publish).SelectReceiver(group.Select(s => s.TransportAddress).ToArray()); addresses.Add(subscriber); } } return(addresses); }
string SelectDestinationAddress(string endpoint, Func <EndpointInstance, string> resolveTransportAddress) { var candidates = endpointInstances.FindInstances(endpoint).Select(resolveTransportAddress).ToArray(); var selected = distributionPolicy.GetDistributionStrategy(endpoint, DistributionStrategyScope.Send).SelectReceiver(candidates); return(selected); }
public string SelectTopicExchangeAddress(string messageId, Dictionary <string, string> headers, ContextBag context) { var addresses = GetAllTopicExchangeAddresses().ToArray(); // NOTE: We don't deserialize the message so we can't create a logical message var distributionContext = new DistributionContext(addresses, NoMessage, messageId, headers, transportAddressTranslation, context); var strategy = distributionPolicy.GetDistributionStrategy(topicExchangeName, DistributionStrategyScope.Send); return(strategy.SelectDestination(distributionContext)); }
public string SelectDestination(string endpoint, string[] addresses, MessageContext context) { // NOTE: We don't deserialize the message so we can't create a logical message var distributionContext = new DistributionContext(addresses, NoMessage, context.MessageId, context.Headers, transportAddressTranslation, context.Extensions); var strategy = distributionPolicy.GetDistributionStrategy(endpoint, DistributionStrategyScope.Publish); var destination = strategy.SelectDestination(distributionContext); return(destination); }
List <(UnicastRoutingStrategy, string)> SelectDestinationsForEachEndpoint(IOutgoingPublishContext publishContext, IDistributionPolicy distributionPolicy, IEnumerable <Subscriber> subscribers) { //Make sure we are sending only one to each transport destination. Might happen when there are multiple routing information sources. var addresses = new Dictionary <string, UnicastRoutingStrategy>(); Dictionary <string, List <string> > groups = null; var results = new List <(UnicastRoutingStrategy, string)>(); foreach (var subscriber in subscribers) { if (subscriber.Endpoint == null) { if (!addresses.ContainsKey(subscriber.TransportAddress)) { var strategy = new UnicastRoutingStrategy(subscriber.TransportAddress); addresses.Add(subscriber.TransportAddress, strategy); results.Add((strategy, null)); logger.Warn($"Subscription {subscriber.TransportAddress} comes from NServiceBus endpoint older than V6. That endpoint needs to be upgraded to at least V6 and restarted in order to be migrated to the new transport."); } continue; } groups = groups ?? new Dictionary <string, List <string> >(); if (groups.TryGetValue(subscriber.Endpoint, out var transportAddresses)) { transportAddresses.Add(subscriber.TransportAddress); } else { groups[subscriber.Endpoint] = new List <string> { subscriber.TransportAddress }; } } if (groups != null) { foreach (var group in groups) { var instances = group.Value.ToArray(); // could we avoid this? var distributionContext = new DistributionContext(instances, publishContext.Message, publishContext.MessageId, publishContext.Headers, transportAddressTranslation, publishContext.Extensions); var subscriber = distributionPolicy.GetDistributionStrategy(group.Key, DistributionStrategyScope.Publish).SelectDestination(distributionContext); if (!addresses.ContainsKey(subscriber)) { var strategy = new UnicastRoutingStrategy(subscriber); addresses.Add(subscriber, strategy); results.Add((strategy, group.Key)); } } } return(results); }
public void When_strategy_configured_for_endpoint_should_use_configured_strategy() { var p = new DistributionPolicy(); var configuredStrategy = new FakeDistributionStrategy("SomeEndpoint", DistributionStrategyScope.Send); p.SetDistributionStrategy(configuredStrategy); IDistributionPolicy policy = p; var result = policy.GetDistributionStrategy("SomeEndpoint", DistributionStrategyScope.Send); Assert.That(result, Is.EqualTo(configuredStrategy)); }
public void When_multiple_strategies_configured_endpoint_should_use_last_configured_strategy() { var p = new DistributionPolicy(); var strategy1 = new FakeDistributionStrategy("SomeEndpoint", DistributionStrategyScope.Send); var strategy2 = new FakeDistributionStrategy("SomeEndpoint", DistributionStrategyScope.Send); p.SetDistributionStrategy(strategy1); p.SetDistributionStrategy(strategy2); IDistributionPolicy policy = p; var result = policy.GetDistributionStrategy("SomeEndpoint", DistributionStrategyScope.Send); Assert.That(result, Is.EqualTo(strategy2)); }
Dictionary <string, UnicastRoutingStrategy> .ValueCollection SelectDestinationsForEachEndpoint(IOutgoingPublishContext publishContext, IDistributionPolicy distributionPolicy, IEnumerable <Subscriber> subscribers) { //Make sure we are sending only one to each transport destination. Might happen when there are multiple routing information sources. var addresses = new Dictionary <string, UnicastRoutingStrategy>(); Dictionary <string, List <string> > groups = null; foreach (var subscriber in subscribers) { if (subscriber.Endpoint == null) { if (!addresses.ContainsKey(subscriber.TransportAddress)) { addresses.Add(subscriber.TransportAddress, new UnicastRoutingStrategy(subscriber.TransportAddress)); } continue; } groups = groups ?? new Dictionary <string, List <string> >(); List <string> transportAddresses; if (groups.TryGetValue(subscriber.Endpoint, out transportAddresses)) { transportAddresses.Add(subscriber.TransportAddress); } else { groups[subscriber.Endpoint] = new List <string> { subscriber.TransportAddress }; } } if (groups != null) { foreach (var group in groups) { var instances = group.Value.ToArray(); // could we avoid this? var distributionContext = new DistributionContext(instances, publishContext.Message, publishContext.MessageId, publishContext.Headers, transportAddressTranslation, publishContext.Extensions); var subscriber = distributionPolicy.GetDistributionStrategy(group.Key, DistributionStrategyScope.Publish).SelectDestination(distributionContext); if (!addresses.ContainsKey(subscriber)) { addresses.Add(subscriber, new UnicastRoutingStrategy(subscriber)); } } } return(addresses.Values); }
IEnumerable <string> SelectDestinationsForEachEndpoint(IEnumerable <Subscriber> subscribers) { //Make sure we are sending only one to each transport destination. Might happen when there are multiple routing information sources. var addresses = new HashSet <string>(); Dictionary <string, List <string> > groups = null; foreach (var subscriber in subscribers) { if (subscriber.Endpoint == null) { addresses.Add(subscriber.TransportAddress); continue; } groups = groups ?? new Dictionary <string, List <string> >(); List <string> transportAddresses; if (groups.TryGetValue(subscriber.Endpoint, out transportAddresses)) { transportAddresses.Add(subscriber.TransportAddress); } else { groups[subscriber.Endpoint] = new List <string> { subscriber.TransportAddress }; } } if (groups != null) { foreach (var group in groups) { var instances = group.Value.ToArray(); // could we avoid this? var subscriber = distributionPolicy.GetDistributionStrategy(group.Key, DistributionStrategyScope.Publish).SelectReceiver(instances); addresses.Add(subscriber); } } return(addresses); }
public UnicastRoutingStrategy Route(Type messageType, IDistributionPolicy distributionPolicy) { var route = unicastRoutingTable.GetRouteFor(messageType); if (route == null) { return null; } if (route.PhysicalAddress != null) { return new UnicastRoutingStrategy(route.PhysicalAddress); } if (route.Instance != null) { return new UnicastRoutingStrategy(transportAddressTranslation(route.Instance)); } var instances = endpointInstances.FindInstances(route.Endpoint).Select(e => transportAddressTranslation(e)).ToArray(); var selectedInstanceAddress = distributionPolicy.GetDistributionStrategy(route.Endpoint, DistributionStrategyScope.Send).SelectReceiver(instances); return new UnicastRoutingStrategy(selectedInstanceAddress); }
static string InvokeDistributionStrategy(IDistributionPolicy policy, string endpointName, string[] instanceAddress) { return(policy.GetDistributionStrategy(endpointName, DistributionStrategyScope.Send).SelectReceiver(instanceAddress)); }
static string InvokeDistributionStrategy(IDistributionPolicy policy, string endpointName, string[] instanceAddress) { return(policy.GetDistributionStrategy(endpointName, DistributionStrategyScope.Send).SelectDestination(new DistributionContext(instanceAddress, null, null, null, null, null))); }
static string InvokeDistributionStrategy(IDistributionPolicy policy, string endpointName, string[] instanceAddress) { return policy.GetDistributionStrategy(endpointName, DistributionStrategyScope.Send).SelectReceiver(instanceAddress); }