예제 #1
0
        public ConnectHandle ConnectSaga(IConsumePipeConnector consumePipe, ISagaRepository <TSaga> repository, ISagaSpecification <TSaga> specification)
        {
            ISagaMessageSpecification <TSaga, TMessage> messageSpecification = specification.GetMessageSpecification <TMessage>();

            IPipe <SagaConsumeContext <TSaga, TMessage> > consumerPipe = messageSpecification.BuildConsumerPipe(_consumeFilter);

            IPipe <ConsumeContext <TMessage> > messagePipe = messageSpecification.BuildMessagePipe(x =>
            {
                ConfigureMessagePipe(x, repository, consumerPipe);
            });

            return(ConfigureConsumeTopology
                ? consumePipe.ConnectConsumePipe(messagePipe)
                : consumePipe.ConnectConsumePipe(messagePipe, NotConfigureConsumeTopology));
        }
예제 #2
0
        public ConnectHandle ConnectConsumer(IConsumePipeConnector consumePipe, IConsumerFactory <TConsumer> consumerFactory,
                                             IConsumerSpecification <TConsumer> specification)
        {
            IConsumerMessageSpecification <TConsumer, TMessage> messageSpecification = specification.GetMessageSpecification <TMessage>();

            IPipe <ConsumerConsumeContext <TConsumer, TMessage> > consumerPipe = messageSpecification.Build(_consumeFilter);

            IPipe <ConsumeContext <TMessage> > messagePipe = messageSpecification.BuildMessagePipe(x =>
            {
                x.UseFilter(new ConsumerMessageFilter <TConsumer, TMessage>(consumerFactory, consumerPipe));
            });

            return(ConfigureConsumeTopology
                ? consumePipe.ConnectConsumePipe(messagePipe)
                : consumePipe.ConnectConsumePipe(messagePipe, NotConfigureConsumeTopology));
        }
예제 #3
0
        ConnectHandle IInstanceMessageConnector <TConsumer> .ConnectInstance(IConsumePipeConnector pipeConnector, TConsumer instance,
                                                                             IConsumerSpecification <TConsumer> specification)
        {
            if (pipeConnector == null)
            {
                throw new ArgumentNullException(nameof(pipeConnector));
            }
            if (instance == null)
            {
                throw new ArgumentNullException(nameof(instance));
            }
            if (specification == null)
            {
                throw new ArgumentNullException(nameof(specification));
            }

            IConsumerMessageSpecification <TConsumer, TMessage> messageSpecification = specification.GetMessageSpecification <TMessage>();

            IPipe <ConsumerConsumeContext <TConsumer, TMessage> > consumerPipe = messageSpecification.Build(_consumeFilter);

            IPipe <ConsumeContext <TMessage> > messagePipe = Pipe.New <ConsumeContext <TMessage> >(x =>
            {
                x.UseFilter(new InstanceMessageFilter <TConsumer, TMessage>(instance, consumerPipe));
            });

            return(pipeConnector.ConnectConsumePipe(messagePipe));
        }
        public ConnectHandle ConnectConsumer(IConsumePipeConnector consumePipe, IConsumerFactory <TConsumer> consumerFactory,
                                             IConsumerSpecification <TConsumer> specification)
        {
            var options = specification.Options <BatchOptions>();

            var messageLimit     = options.MessageLimit;
            var timeLimit        = options.TimeLimit;
            var concurrencyLimit = options.ConcurrencyLimit;

            IConsumerMessageSpecification <TConsumer, Batch <TMessage> > batchMessageSpecification = specification.GetMessageSpecification <Batch <TMessage> >();

            var consumeFilter = new MethodConsumerMessageFilter <TConsumer, Batch <TMessage> >();

            IPipe <ConsumerConsumeContext <TConsumer, Batch <TMessage> > > batchConsumerPipe = batchMessageSpecification.Build(consumeFilter);

            var factory = new BatchConsumerFactory <TConsumer, TMessage>(consumerFactory, messageLimit, concurrencyLimit, timeLimit, batchConsumerPipe);

            IConsumerSpecification <IConsumer <TMessage> > messageConsumerSpecification =
                ConsumerConnectorCache <IConsumer <TMessage> > .Connector.CreateConsumerSpecification <IConsumer <TMessage> >();

            IConsumerMessageSpecification <IConsumer <TMessage>, TMessage> messageSpecification =
                messageConsumerSpecification.GetMessageSpecification <TMessage>();

            IPipe <ConsumerConsumeContext <IConsumer <TMessage>, TMessage> > consumerPipe =
                messageSpecification.Build(new MethodConsumerMessageFilter <IConsumer <TMessage>, TMessage>());

            IPipe <ConsumeContext <TMessage> > messagePipe = messageSpecification.BuildMessagePipe(x =>
            {
                x.UseFilter(new ConsumerMessageFilter <IConsumer <TMessage>, TMessage>(factory, consumerPipe));
            });

            var handle = consumePipe.ConnectConsumePipe(messagePipe);

            return(new BatchConnectHandle(handle, factory));
        }
예제 #5
0
        public ConnectHandle ConnectHandler(IConsumePipeConnector consumePipe, MessageHandler <TMessage> handler,
                                            IBuildPipeConfigurator <ConsumeContext <TMessage> > configurator)
        {
            configurator ??= new PipeConfigurator <ConsumeContext <TMessage> >();
            configurator.AddPipeSpecification(new HandlerPipeSpecification <TMessage>(handler));

            return(consumePipe.ConnectConsumePipe(configurator.Build()));
        }
예제 #6
0
        private void ConnectPipe <TMessage>(IConsumePipeConnector pipeConnector) where TMessage : class
        {
            var pipe = Pipe.New <ConsumeContext <TMessage> >(cfg =>
            {
                cfg.UseExecute(ctx => _workflow.ConsumeMessage(ctx.Message));
            });

            pipeConnector.ConnectConsumePipe(pipe);
        }
        public ConnectHandle ConnectConsumePipe <T>(IPipe <ConsumeContext <T> > pipe)
            where T : class
        {
            if (pipe == null)
            {
                throw new ArgumentNullException(nameof(pipe));
            }

            IConsumePipeConnector <T> messagePipe = GetPipe <T, IConsumePipeConnector <T> >();

            return(messagePipe.ConnectConsumePipe(pipe));
        }
예제 #8
0
        public ConnectHandle ConnectHandler(IConsumePipeConnector consumePipe, MessageHandler <TMessage> handler,
                                            params IPipeSpecification <ConsumeContext <TMessage> >[] pipeSpecifications)
        {
            IPipe <ConsumeContext <TMessage> > pipe = Pipe.New <ConsumeContext <TMessage> >(x =>
            {
                foreach (var specification in pipeSpecifications)
                {
                    x.AddPipeSpecification(specification);
                }

                x.AddPipeSpecification(new HandlerPipeSpecification <TMessage>(handler));
            });

            return(consumePipe.ConnectConsumePipe(pipe));
        }
        public ConnectHandle ConnectObserver(IConsumePipeConnector consumePipe, IObserver <ConsumeContext <TMessage> > observer,
                                             params IFilter <ConsumeContext <TMessage> >[] filters)
        {
            IPipe <ConsumeContext <TMessage> > pipe = Pipe.New <ConsumeContext <TMessage> >(x =>
            {
                foreach (IFilter <ConsumeContext <TMessage> > filter in filters)
                {
                    x.UseFilter(filter);
                }

                x.AddPipeSpecification(new ObserverPipeSpecification <TMessage>(observer));
            });

            return(consumePipe.ConnectConsumePipe(pipe));
        }
예제 #10
0
        ConnectHandle IConsumerConnector.ConnectConsumer <T>(IConsumePipeConnector consumePipe, IConsumerFactory <T> consumerFactory,
                                                             IPipeSpecification <ConsumerConsumeContext <T> >[] pipeSpecifications)
        {
            var factory = consumerFactory as IConsumerFactory <TConsumer>;

            if (factory == null)
            {
                throw new ArgumentException("The consumer factory type does not match: " + TypeMetadataCache <T> .ShortName);
            }

            IPipe <ConsumerConsumeContext <TConsumer, TMessage> > consumerPipe = ConsumerPipeBuilder.BuildConsumerPipe(_consumeFilter, pipeSpecifications);

            IPipe <ConsumeContext <TMessage> > messagePipe = MessagePipeBuilder.BuildMessagePipe <TConsumer, TMessage, T>(pipeSpecifications, new ConsumerMessageFilter <TConsumer, TMessage>(factory, consumerPipe));

            return(consumePipe.ConnectConsumePipe(messagePipe));
        }
예제 #11
0
        ConnectHandle ISagaConnector.ConnectSaga <T>(IConsumePipeConnector consumePipe, ISagaRepository <T> sagaRepository,
                                                     params IPipeSpecification <SagaConsumeContext <T> >[] pipeSpecifications)
        {
            var repository = sagaRepository as ISagaRepository <TSaga>;

            if (repository == null)
            {
                throw new ArgumentException("The saga repository type does not match: " + TypeMetadataCache <T> .ShortName);
            }

            var sagaPipe = BuildSagaPipe(pipeSpecifications);

            var messagePipe = BuildMessagePipe(pipeSpecifications, repository, sagaPipe);

            return(consumePipe.ConnectConsumePipe(messagePipe));
        }
        ConnectHandle ISagaConnector.ConnectSaga <T>(IConsumePipeConnector consumePipe, ISagaRepository <T> sagaRepository,
                                                     params IPipeSpecification <SagaConsumeContext <T> >[] pipeSpecifications)
        {
            var repository = sagaRepository as ISagaRepository <TSaga>;

            if (repository == null)
            {
                throw new ArgumentException("The saga repository type does not match: " + TypeMetadataCache <T> .ShortName);
            }

            var builder = new SagaPipeBuilder <T>();

            for (int i = 0; i < pipeSpecifications.Length; i++)
            {
                pipeSpecifications[i].Apply(builder);
            }

            var builders = builder as SagaPipeBuilder <TSaga>;

            if (builders == null)
            {
                throw new InvalidOperationException("Should not be null, ever");
            }

            IPipe <SagaConsumeContext <TSaga, TMessage> > sagaPipe = Pipe.New <SagaConsumeContext <TSaga, TMessage> >(x =>
            {
                foreach (var filter in builders.Filters)
                {
                    x.Filter(filter);
                }

                ConfigureSagaPipe(x);
            });

            IPipe <ConsumeContext <TMessage> > messagePipe = Pipe.New <ConsumeContext <TMessage> >(x =>
            {
                ConfigureMessagePipe(x, repository, sagaPipe);
            });

            return(consumePipe.ConnectConsumePipe(messagePipe));
        }
예제 #13
0
        ConnectHandle IInstanceConnector.ConnectInstance(IConsumePipeConnector pipe, object instance)
        {
            if (instance == null)
            {
                throw new ArgumentNullException(nameof(instance));
            }

            var consumer = instance as TConsumer;

            if (consumer == null)
            {
                throw new ConsumerException(
                          $"The instance type {instance.GetType().GetTypeName()} does not match the consumer type: {TypeMetadataCache<TConsumer>.ShortName}");
            }

            IPipe <ConsumeContext <TMessage> > instancePipe = Pipe.New <ConsumeContext <TMessage> >(x =>
            {
                x.UseFilter(new InstanceMessageFilter <TConsumer, TMessage>(consumer, _consumeFilter));
            });

            return(pipe.ConnectConsumePipe(instancePipe));
        }
예제 #14
0
        ConnectHandle IConsumerConnector.ConnectConsumer <T>(IConsumePipeConnector consumePipe, IConsumerFactory <T> consumerFactory,
                                                             IPipeSpecification <ConsumerConsumeContext <T> >[] pipeSpecifications)
        {
            var factory = consumerFactory as IConsumerFactory <TConsumer>;

            if (factory == null)
            {
                throw new ArgumentException("The consumer factory type does not match: " + TypeMetadataCache <T> .ShortName);
            }

            var builder = new ConsumerPipeBuilder <T>();

            for (int i = 0; i < pipeSpecifications.Length; i++)
            {
                pipeSpecifications[i].Apply(builder);
            }

            var builders = builder as ConsumerPipeBuilder <TConsumer>;

            if (builders == null)
            {
                throw new InvalidOperationException("Should not be null, ever");
            }

            IPipe <ConsumerConsumeContext <TConsumer, TMessage> > messagePipe = Pipe.New <ConsumerConsumeContext <TConsumer, TMessage> >(x =>
            {
                foreach (var filter in builders.Filters)
                {
                    x.UseFilter(filter);
                }
                x.UseFilter(_consumeFilter);
            });

            IPipe <ConsumeContext <TMessage> > pipe =
                Pipe.New <ConsumeContext <TMessage> >(x => x.UseFilter(new ConsumerMessageFilter <TConsumer, TMessage>(factory, messagePipe)));

            return(consumePipe.ConnectConsumePipe(pipe));
        }
예제 #15
0
        ConnectHandle IInstanceConnector.ConnectInstance <T>(IConsumePipeConnector consumePipe, T instance,
                                                             IPipeSpecification <ConsumerConsumeContext <T> >[] pipeSpecifications)
        {
            if (instance == null)
            {
                throw new ArgumentNullException(nameof(instance));
            }

            var consumer = instance as TConsumer;

            if (consumer == null)
            {
                throw new ConsumerException(
                          $"The instance type {instance.GetType().GetTypeName()} does not match the consumer type: {TypeMetadataCache<TConsumer>.ShortName}");
            }

            IPipe <ConsumerConsumeContext <TConsumer, TMessage> > consumerPipe = ConsumerPipeBuilder.BuildConsumerPipe(_consumeFilter, pipeSpecifications);

            IPipe <ConsumeContext <TMessage> > messagePipe = MessagePipeBuilder.BuildMessagePipe <TConsumer, TMessage, T>(pipeSpecifications,
                                                                                                                          new InstanceMessageFilter <TConsumer, TMessage>(consumer, consumerPipe));

            return(consumePipe.ConnectConsumePipe(messagePipe));
        }