static string[] GetDestinationSites(IOutgoingContext context)
    {
        if (!context.Extensions.TryGet <RouteToSitesBehavior.State>(out var state))
        {
            return(new string[0]);
        }

        return(state.Sites);
    }
Пример #2
0
        private static void AttachCatHeaders(IAgentWrapperApi agentWrapperApi, IOutgoingContext context)
        {
            var outboundRequestHeaders = agentWrapperApi.GetOutboundRequestHeaders();

            foreach (var header in outboundRequestHeaders)
            {
                if (header.Value != null && header.Key != null)
                {
                    context.Headers[header.Key] = header.Value;
                }
            }
        }
    public IEnumerable <RoutingStrategy> Route(Type messageType, IOutgoingContext context, OutgoingLogicalMessage outgoingMessage, DistributionStrategyScope distributionStrategyScope)
    {
        var routes = routeGenerator.GetRoutesFor(messageType);

        var matchingRoutes = routes.Where(r => r.Match(GetDestinationSites(context)));

        foreach (var destination in matchingRoutes)
        {
            var candidates           = ResolveRoute(destination).ToArray();
            var distributionContext  = new DistributionContext(candidates, outgoingMessage, context.MessageId, context.Headers, resolveTransportAddress, context.Extensions);
            var distributionStrategy = distributionPolicy.GetDistributionStrategy(destination.ImmediateDestination, distributionStrategyScope);
            var selected             = distributionStrategy.SelectDestination(distributionContext);

            var routingStrategy = new MapBasedRoutingStrategy(selected, destination.NextHop);
            yield return(routingStrategy);
        }
    }