예제 #1
0
        public override void Build()
        {
            var hasher            = new ProjectionHasher();
            var builder           = this as ISettingsBuilder;
            var processorSettings = this as ISubscrptionMiddlewareSettings;
            Func <SubscriptionMiddleware> messageHandlerProcessorFactory = () =>
            {
                var handlerFactory = new DefaultHandlerFactory(processorSettings.HandlerFactory);

                var    clusterServiceMiddleware = new SystemMiddleware(handlerFactory);
                var    middleware             = processorSettings.HandleMiddleware(clusterServiceMiddleware);
                var    subscriptionMiddleware = new SubscriptionMiddleware();
                var    clusterSettings        = builder.Container.Resolve <IClusterSettings>();
                string nodeId = $"{clusterSettings.CurrentNodeName}@{clusterSettings.ClusterName}";
                foreach (var reg in (this as ISubscrptionMiddlewareSettings).HandlerRegistrations)
                {
                    string subscriberId = reg.FullName + "." + nodeId;
                    if (typeof(ISystemProjection).IsAssignableFrom(reg) && reg.IsClass)
                    {
                        subscriptionMiddleware.Subscribe(new SystemProjectionSubscriber(reg, middleware, subscriberId));

                        var transport     = builder.Container.Resolve <ITransport>(builder.Name);
                        var serializer    = builder.Container.Resolve <ISerializer>(null);
                        var publisher     = transport.GetPublisher <ICommand>(serializer);
                        var projManagerId = new ProjectionVersionManagerId(reg.GetContractId());
                        var command       = new RegisterProjection(projManagerId, hasher.CalculateHash(reg).ToString());
                        publisher.Publish(command);
                    }
                }
                return(subscriptionMiddleware);
            };

            builder.Container.RegisterSingleton <SubscriptionMiddleware>(() => messageHandlerProcessorFactory(), builder.Name);
        }
        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 routingHeaders = item.Value
                               .Distinct()
                               .ToDictionary<Type, string, object>(key => key.GetContractId(), val => String.Empty);
                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, routingHeaders);
            }
        }
        public override void Build()
        {
            var builder           = this as ISettingsBuilder;
            var processorSettings = this as ISubscrptionMiddlewareSettings;
            Func <SubscriptionMiddleware> messageHandlerProcessorFactory = () =>
            {
                var handlerFactory = new DefaultHandlerFactory(processorSettings.HandlerFactory);
                var repository     = builder.Container.Resolve <IAggregateRepository>(builder.Name);
                var publisher      = builder.Container.Resolve <IPublisher <IEvent> >(builder.Name);

                //create extension methis UseApplicationMiddleware instead of instance here.
                var applicationServiceMiddleware = new ApplicationServiceMiddleware(handlerFactory, repository, publisher);
                var middleware             = processorSettings.HandleMiddleware(applicationServiceMiddleware);
                var subscriptionMiddleware = new SubscriptionMiddleware();
                foreach (var reg in (this as ISubscrptionMiddlewareSettings).HandlerRegistrations)
                {
                    if (typeof(IAggregateRootApplicationService).IsAssignableFrom(reg))
                    {
                        subscriptionMiddleware.Subscribe(new HandleSubscriber <IAggregateRootApplicationService, ICommandHandler <ICommand> >(reg, middleware));
                    }
                }
                return(subscriptionMiddleware);
            };

            builder.Container.RegisterSingleton <SubscriptionMiddleware>(() => messageHandlerProcessorFactory(), builder.Name);
        }
 public RabbitMqContiniousConsumerFactory(string consumerName, ISerializer serializer, IConnectionFactory connectionFactory, SubscriptionMiddleware middleware)
 {
     this.consumerName      = consumerName;
     this.serializer        = serializer;
     this.connectionFactory = connectionFactory;
     this.middleware        = middleware;
 }
예제 #5
0
        /// <summary>
        /// Initializes a new instance of the <see cref="EndpointConsumer"/> class.
        /// </summary>
        /// <param name="transport">The transport.</param>
        /// <param name="serializer">The serializer.</param>
        /// <param name="messageThreshold">The message threshold.</param>
        public EndpointConsumer(string name, IPipelineTransport transport, SubscriptionMiddleware subscriptions, ISerializer serializer, MessageThreshold messageThreshold = null)
        {
            if (string.IsNullOrEmpty(name))
            {
                throw new ArgumentException("Invalid consumer name", nameof(name));
            }
            if (ReferenceEquals(null, transport))
            {
                throw new ArgumentNullException(nameof(transport));
            }
            if (ReferenceEquals(null, subscriptions))
            {
                throw new ArgumentNullException(nameof(subscriptions));
            }
            if (subscriptions.Subscribers.Count() == 0)
            {
                throw new ArgumentException("A consumer must have at least one subscriber to work properly.", nameof(subscriptions));
            }
            if (ReferenceEquals(null, serializer))
            {
                throw new ArgumentNullException(nameof(serializer));
            }

            this.Name          = name;
            NumberOfWorkers    = 1;
            this.subscriptions = subscriptions;
            this.transport     = transport;
            this.serializer    = serializer;
            pools = new List <WorkPool>();
            this.messageThreshold = messageThreshold ?? new MessageThreshold();
        }
예제 #6
0
 public PipelineConsumerWork(SubscriptionMiddleware subscriptions, IEndpoint endpoint, ISerializer serializer, MessageThreshold messageThreshold)
 {
     this.endpoint         = endpoint;
     this.subscriptions    = subscriptions;
     this.serializer       = serializer;
     this.messageThreshold = messageThreshold;
 }
예제 #7
0
        public override void Build()
        {
            var builder           = this as ISettingsBuilder;
            var processorSettings = this as ISubscrptionMiddlewareSettings;
            Func <SubscriptionMiddleware> messageHandlerProcessorFactory = () =>
            {
                var handlerFactory = new DefaultHandlerFactory(processorSettings.HandlerFactory);

                var publisher  = builder.Container.Resolve <IPublisher <IEvent> >(builder.Name);
                var repository = builder.Container.Resolve <IAggregateRepository>(builder.Name);
                var systemServiceMiddleware = new ApplicationServiceMiddleware(handlerFactory, repository, publisher);
                var middleware             = processorSettings.HandleMiddleware(systemServiceMiddleware);
                var subscriptionMiddleware = new SubscriptionMiddleware();
                foreach (var reg in (this as ISubscrptionMiddlewareSettings).HandlerRegistrations)
                {
                    if (typeof(ISystemService).IsAssignableFrom(reg) && reg.IsClass)
                    {
                        subscriptionMiddleware.Subscribe(new SystemServiceSubscriber(reg, middleware));
                    }
                }
                return(subscriptionMiddleware);
            };

            builder.Container.RegisterSingleton <SubscriptionMiddleware>(() => messageHandlerProcessorFactory(), builder.Name);
        }
        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 routingHeaders = subscriptionMiddleware.Subscribers.SelectMany(x => x.MessageTypes)
                                                        .Distinct()
                                                        .ToDictionary<Type, string, object>(key => key.GetContractId(), val => String.Empty);

            EndpointDefinition endpointDefinition = new EndpointDefinition(pipeLine.Single(), consumer.Name, routingHeaders);
            yield return endpointDefinition;
        }
예제 #9
0
        /// <summary>
        /// Initializes a new instance of the <see cref="ReduxStore{T}" class/>
        /// </summary>
        /// <param name="reducer">Reducer to use for state transformations.</param>
        /// <param name="initialStateFactory">Factory used to create the initial state of the application.</param>
        public ReduxStore(
            IReduxReducer <T> reducer,
            IReduxStateFactory <T> initialStateFactory)
        {
            if (initialStateFactory is null)
            {
                throw new ArgumentNullException(nameof(initialStateFactory));
            }

            _subscriptions = new SubscriptionMiddleware(this);

            _reducer = new ReducingMiddleware(
                reducer ?? throw new ArgumentNullException(nameof(reducer)),
                initialStateFactory.Create());

            _processingQueue
                = new Cached <ImmutableQueue <IReduxMiddleware> >(
                      CreateProcessingQueue);
        }
예제 #10
0
        public override void Build()
        {
            var builder           = this as ISettingsBuilder;
            var processorSettings = this as ISubscrptionMiddlewareSettings;
            Func <SubscriptionMiddleware> messageHandlerProcessorFactory = () =>
            {
                var handlerFactory         = new DefaultHandlerFactory(processorSettings.HandlerFactory);
                var publisher              = builder.Container.Resolve <IPublisher <ICommand> >(builder.Name);
                var portsMiddleware        = new PortsMiddleware(handlerFactory, publisher);
                var middleware             = processorSettings.HandleMiddleware(portsMiddleware);
                var subscriptionMiddleware = new SubscriptionMiddleware();
                foreach (var reg in (this as ISubscrptionMiddlewareSettings).HandlerRegistrations)
                {
                    if (typeof(IPort).IsAssignableFrom(reg))
                    {
                        subscriptionMiddleware.Subscribe(new HandleSubscriber <IPort, IEventHandler <IEvent> >(reg, middleware));
                    }
                }
                return(subscriptionMiddleware);
            };

            builder.Container.RegisterSingleton <SubscriptionMiddleware>(() => messageHandlerProcessorFactory(), builder.Name);
        }
예제 #11
0
        public override void Build()
        {
            var hasher            = new ProjectionHasher();
            var builder           = this as ISettingsBuilder;
            var processorSettings = this as ISubscrptionMiddlewareSettings;
            Func <SubscriptionMiddleware> messageHandlerProcessorFactory = () =>
            {
                var handlerFactory = new DefaultHandlerFactory(processorSettings.HandlerFactory);

                //  May be we want to have separate serializer + transport per type?!?!?
                var transport  = builder.Container.Resolve <ITransport>(builder.Name);
                var serializer = builder.Container.Resolve <ISerializer>(null);
                var publisher  = transport.GetPublisher <ICommand>(serializer);

                var projectionsMiddleware  = new ProjectionsMiddleware(handlerFactory);
                var middleware             = processorSettings.HandleMiddleware(projectionsMiddleware);
                var subscriptionMiddleware = new SubscriptionMiddleware();
                var iProjection            = typeof(IProjection);

                foreach (var handler in processorSettings.HandlerRegistrations)
                {
                    if (iProjection.IsAssignableFrom(handler))
                    {
                        subscriptionMiddleware.Subscribe(new HandlerSubscriber <IProjection, IEventHandler <IEvent> >(handler, middleware));
                        var projManagerId = new ProjectionVersionManagerId(handler.GetContractId());
                        var command       = new RegisterProjection(projManagerId, hasher.CalculateHash(handler).ToString());
                        publisher.Publish(command);
                    }
                }
                var indexSubscriber = builder.Container.Resolve <EventTypeIndexForProjections>();
                subscriptionMiddleware.Subscribe(indexSubscriber);
                return(subscriptionMiddleware);
            };

            builder.Container.RegisterSingleton <SubscriptionMiddleware>(() => messageHandlerProcessorFactory(), builder.Name);
        }
 public QueueingBasicConsumerWithManagedConnection(IConnectionFactory connectionFactory, SubscriptionMiddleware middleware, string consumerName)
 {
     this.connectionFactory = connectionFactory;
     this.middleware        = middleware;
     this.consumerName      = consumerName;
 }
예제 #13
0
 public abstract System.Collections.Generic.IEnumerable <EndpointDefinition> GetEndpointDefinition(IEndpointConsumer consumer, SubscriptionMiddleware subscriptionMiddleware);
예제 #14
0
 public IEnumerable <EndpointDefinition> GetEndpointDefinition(IEndpointConsumer consumer, SubscriptionMiddleware subscriptionMiddleware)
 {
     return(endpointNameConvention.GetEndpointDefinition(consumer, subscriptionMiddleware));
 }
 public RabbitMqContinuousConsumer(string consumerName, ISerializer serializer, IConnectionFactory connectionFactory, SubscriptionMiddleware middleware) : base(middleware)
 {
     this.deliveryTags = new Dictionary <Guid, ulong>();
     this.serializer   = serializer;
     this.consumer     = new QueueingBasicConsumerWithManagedConnection(connectionFactory, middleware, consumerName);
 }
예제 #16
0
 public IEnumerable<EndpointDefinition> GetEndpointDefinition(IEndpointConsumer consumer, SubscriptionMiddleware subscriptionMiddleware)
 {
     yield return endpoint;
 }
예제 #17
0
        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));
            }
        }
예제 #18
0
        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);
        }
예제 #19
0
 public InMemoryPublisher(SubscriptionMiddleware messageProcessor)
 {
     this.subscribtions = messageProcessor;
 }
 public IEnumerable<EndpointDefinition> GetEndpointDefinition(IEndpointConsumer consumer, SubscriptionMiddleware subscriptionMiddleware)
 {
     return endpointNameConvention.GetEndpointDefinition(consumer, subscriptionMiddleware);
 }
예제 #21
0
 public IEnumerable <IConsumerFactory> GetAvailableConsumers(ISerializer serializer, SubscriptionMiddleware subscriptions, string consumerName)
 {
     var messageType = subscriptions.Subscribers.FirstOrDefault().GetInvolvedMessageTypes().FirstOrDefault();
     var name        = RabbitMqNamer.GetBoundedContext(messageType).ProductNamespace + "." + consumerName;
     //foreach (var item in subscriptions.Subscribers)
     {
         yield return(new RabbitMqContiniousConsumerFactory(name, serializer, connectionFactory, subscriptions));
     }
 }
예제 #22
0
 public ContinuousConsumer(SubscriptionMiddleware subscriptions)
 {
     this.subscriptions = subscriptions;
     isRunning          = true;
 }