public Endpoint Resolve(string route, RoutingKey key, IEndpointProvider endpointProvider) { var endpointName = m_Map.Where(pair => pair.Key(key)).Select(pair => pair.Value).SingleOrDefault(); if (endpointName == null) { return(m_FallbackResolver.Resolve(route, key, endpointProvider)); } return(endpointProvider.Get(endpointName)); }
private void init() { foreach (var registration in m_Registrations) { registration.Create(this); } foreach (var registration in m_Registrations) { registration.Process(this); } foreach (var boundedContext in BoundedContexts) { boundedContext.Processes.ForEach(p => p.Start(this, boundedContext.EventsPublisher)); } var boundedContextsWithWrongLocal = m_BoundedContexts.Where(bc => m_BoundedContexts.All(b => b.Name != bc.LocalBoundedContext || !b.IsLocal)).ToArray(); if (boundedContextsWithWrongLocal.Any()) { throw new ConfigurationErrorsException("Following bounded contexts are mapped to not existing local bounded context: " + string.Join(", ", boundedContextsWithWrongLocal.Select(s => string.Format("'{0}'", s.Name)))); } ensureEndpoints(); foreach (var boundedContext in BoundedContexts) { foreach (var eventsSubscription in boundedContext.EventsSubscriptions) { var route = eventsSubscription.Key; var boundedContextName = boundedContext.Name; var localBoundedContextName = boundedContext.LocalBoundedContext; var groupedBySubscribeEndpoint = eventsSubscription.Value.GroupBy(type => { var e = m_EndpointResolver.Resolve(localBoundedContextName, boundedContextName, route, type, RouteType.Events); return(new Endpoint(e.TransportId, "", e.Destination.Subscribe, e.SharedDestination, e.SerializationFormat)); }); foreach (var group in groupedBySubscribeEndpoint) { BoundedContext context = boundedContext; m_Subscription.Add(m_MessagingEngine.Subscribe( group.Key, (@event, acknowledge) => context.EventDispatcher.Dispacth(@event, acknowledge), (type, acknowledge) => { throw new InvalidOperationException("Unknown event received: " + type); //acknowledge(0, true); }, route, 0, group.ToArray())); } } } foreach (var boundedContext in BoundedContexts) { foreach (var commandsSubscription in boundedContext.CommandsSubscriptions) { var route = commandsSubscription.Endpoint; var boundedContextName = boundedContext.Name; var localBoundedContextName = boundedContext.LocalBoundedContext; var groupedBySubscribeEndpoint = commandsSubscription.Types.GroupBy(t => { var type = t.Key; var commandPriority = t.Value; var e = m_EndpointResolver.Resolve(localBoundedContextName, boundedContextName, route, type, RouteType.Commands); return(new { endpoint = new Endpoint(e.TransportId, "", e.Destination.Subscribe, e.SharedDestination, e.SerializationFormat), priority = commandPriority }); }); BoundedContext context = boundedContext; //TODO: use messaging priority processing foreach (var group in groupedBySubscribeEndpoint) { var g = @group.Key; m_Subscription.Add(m_MessagingEngine.Subscribe( g.endpoint, (command, acknowledge) => context.CommandDispatcher.Dispatch(command, g.priority, acknowledge, g.endpoint, route), (type, acknowledge) => { throw new InvalidOperationException("Unknown command received: " + type); //acknowledge(0, true); }, route, 0, group.Select(gr => gr.Key).ToArray() )); } /* * var endpoint = m_EndpointResolver.Resolve(boundedContext.Name, commandsSubscription.Endpoint); * BoundedContext context = boundedContext; * CommandSubscription commandSubscription = commandsSubscription; * m_Subscription.Add(m_MessagingEngine.Subscribe( * endpoint, * (command, acknowledge) => * context.CommandDispatcher.Dispatch(command, commandSubscription.Types[command.GetType()], * acknowledge, endpoint), * (type, acknowledge) => * { * throw new InvalidOperationException("Unknown command received: " + type); * //acknowledge(0, true); * }, * commandSubscription.Types.Keys.ToArray())); */ } } }