static string ExtractDestination(UnicastRoutingStrategy route) { var headers = new Dictionary <string, string>(); var addressTag = (UnicastAddressTag)route.Apply(headers); return(addressTag.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 override async Task Invoke(IIncomingPhysicalMessageContext context, Func <Task> next, Func <IRoutingContext, Task> fork) { var messageToForward = new OutgoingMessage( context.Message.MessageId, new Dictionary <string, string>(context.Message.Headers), context.Message.Body); await next() .ConfigureAwait(false); var forwardingRoutingStrategy = new UnicastRoutingStrategy(forwardingAddress); var routingContext = new ForwardedRoutingContext( messageToForward, forwardingRoutingStrategy, context); await fork(routingContext) .ConfigureAwait(false); }
public MigratorRouterRoutingStrategy(string routerAddress, UnicastRoutingStrategy unicastStrategy) { this.routerAddress = routerAddress; this.unicastStrategy = unicastStrategy; }
public void AddRoutingStrategy(UnicastRoutingStrategy forwardingRoutingStrategy) { routingStrategies.Add(forwardingRoutingStrategy); }