public override IEnumerable <EndpointDefinition> GetEndpointDefinition(IEndpointConsumer consumer, SubscriptionMiddleware subscriptionMiddleware) { var pipeLine = subscriptionMiddleware.Subscribers.Select(x => pipelineNameConvention.GetPipelineName(x.MessageTypes.First())).Distinct(); if (pipeLine.Count() == 0) { throw new ArgumentException("Cannot find pipeline to subscribe to."); } else if (pipeLine.Count() > 1) { throw new ArgumentException("Cannot subscribe to more than one pipeline. Probably you have mixed ICommand and IEvent messages within a single handler."); } var watchMessageTypes = subscriptionMiddleware.Subscribers.SelectMany(x => x.MessageTypes).Distinct().Select(x => x.GetContractId()).ToList(); EndpointDefinition endpointDefinition = new EndpointDefinition(pipeLine.Single(), consumer.Name, watchMessageTypes); yield return(endpointDefinition); }
public IEnumerable <EndpointDefinition> GetEndpointDefinition(IEndpointConsumer consumer, SubscriptionMiddleware subscriptionMiddleware) { Dictionary <string, HashSet <Type> > handlers = new Dictionary <string, HashSet <Type> >(); var subType = typeof(SubscriptionMiddleware); foreach (var item in subscriptionMiddleware.Subscribers) { var messageHandlerType = subType.GetField("messageHandlerType", System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.NonPublic).GetValue(item) as Type; if (!handlers.ContainsKey(item.Id)) { handlers.Add(item.Id, new HashSet <Type>() { }); } foreach (var messageType in item.MessageTypes) { handlers[item.Id].Add(messageType); } } List <string> endpointNames = new List <string>(); foreach (var item in handlers) { var pipelineName = pipelineNameConvention.GetPipelineName(item.Value.First()); var watchMessageTypes = item.Value.Distinct().Select(x => x.GetContractId()).ToList(); var bc = item.Value.First().GetBoundedContext().BoundedContextNamespace; var endpointName = bc + "." + "(" + item.Key + ")"; if (endpointNames.Contains(endpointName)) { throw new InvalidOperationException("Duplicatie endpoint name " + endpointName); } endpointNames.Add(endpointName); yield return(new EndpointDefinition(pipelineName, endpointName, watchMessageTypes)); } }
public IPipeline GetPipeline(Type messageType) { string pipelineName = pipelineNameConvention.GetPipelineName(messageType); return(GetPipeline(pipelineName)); }