Esempio n. 1
0
        public UnsubscribeAction Connect(IInboundPipelineConfigurator configurator, object instance)
        {
            var consumer = instance as TConsumer;

            if (consumer == null)
            {
                throw new NullReferenceException("The consumer instance cannot be null.");
            }

            var correlatedConfigurator = new InboundCorrelatedMessageRouterConfigurator(configurator.Pipeline);

            CorrelatedMessageRouter <IConsumeContext <TMessage>, TMessage, TKey> router =
                correlatedConfigurator.FindOrCreate <TMessage, TKey>();

            var sink = new InstanceMessageSink <TMessage>(MultipleHandlerSelector.ForHandler(
                                                              HandlerSelector.ForHandler <TMessage>(consumer.Consume)));

            TKey correlationId = consumer.CorrelationId;

            UnsubscribeAction result = router.Connect(correlationId, sink);

            UnsubscribeAction remove = configurator.SubscribedTo <TMessage, TKey>(correlationId);

            return(() => result() && (router.SinkCount(correlationId) == 0) && remove());
        }
Esempio n. 2
0
        public UnsubscribeAction Connect(IInboundPipelineConfigurator configurator, object instance)
        {
            var worker = instance as ISagaWorker <TSaga>;
            ISagaMessageSink <TSaga, TMessage> sink = _connector.CreateSink();
            var workerSink = new SagaWorkerMessageSink <TSaga, TMessage>(worker, sink);

            return(configurator.Pipeline.ConnectToRouter(workerSink, () => configurator.SubscribedTo <Distributed <TMessage> >()));
        }
        public UnsubscribeAction Connect(IInboundPipelineConfigurator configurator, IWorker worker)
        {
            IWorkerLoad <TMessage> workerLoad = worker.GetWorkerLoad <TMessage>();

            var consumerSink = new SelectedConsumerMessageSink <TConsumer, TMessage>(_consumerFactory);

            var sink = new WorkerMessageSink <TMessage>(workerLoad, consumerSink);

            return(configurator.Pipeline.ConnectToRouter(sink, () => configurator.SubscribedTo <Distributed <TMessage> >()));
        }
        public UnsubscribeAction Connect(IInboundPipelineConfigurator configurator, IDistributor distributor)
        {
            IWorkerAvailability <TMessage> workerAvailability = distributor.GetWorkerAvailability <TMessage>();

            // TODO we need to make a saga worker availability so that we can split saga load by correlation id
            IWorkerSelector <TMessage> workerSelector = _workerSelectorFactory.GetSelector <TMessage>();

            var sink = new DistributorMessageSink <TMessage>(workerAvailability, workerSelector);

            return(configurator.Pipeline.ConnectToRouter(sink, () => configurator.SubscribedTo <TMessage>()));
        }
Esempio n. 5
0
        public UnsubscribeAction Connect(IInboundPipelineConfigurator configurator, IWorker worker)
        {
            IWorkerLoad <TMessage> workerLoad = worker.GetWorkerLoad <TMessage>();

            ISagaPolicy <TSaga, TMessage> policy = GetPolicy();

            ISagaMessageSink <TSaga, TMessage> messageSink = GetSagaMessageSink(_sagaRepository, policy);

            var sink = new WorkerMessageSink <TMessage>(workerLoad, messageSink);

            return(configurator.Pipeline.ConnectToRouter(sink, () => configurator.SubscribedTo <Distributed <TMessage> >()));
        }
        public UnsubscribeAction Connect(IInboundPipelineConfigurator configurator, object instance)
        {
            var worker = instance as IWorker <TMessage>;

            if (worker == null)
            {
                throw new ConfigurationException("The instance is not a distributor worker");
            }

            var sink = new WorkerMessageSink <Distributed <TMessage> >(MultipleHandlerSelector.ForHandler(
                                                                           HandlerSelector.ForSelectiveHandler <Distributed <TMessage> >(worker.Accept, worker.Consume)));

            return(configurator.Pipeline.ConnectToRouter(sink, () => configurator.SubscribedTo <Distributed <TMessage> >()));
        }
Esempio n. 7
0
        public UnsubscribeAction Connect(IInboundPipelineConfigurator configurator, object instance)
        {
            var consumer = instance as TConsumer;

            if (consumer == null)
            {
                throw new NullReferenceException("The consumer instance cannot be null.");
            }

            var sink = new InstanceMessageSink <TMessage>(MultipleHandlerSelector.ForHandler(
                                                              HandlerSelector.ForSelectiveHandler <TMessage>(consumer.Accept, consumer.Consume)));

            return(configurator.Pipeline.ConnectToRouter(sink, () => configurator.SubscribedTo <TMessage>()));
        }
        public UnsubscribeAction Connect(IInboundPipelineConfigurator configurator, HandlerSelector <TMessage> handler)
        {
            var routerConfigurator = new InboundMessageRouterConfigurator(configurator.Pipeline);

            MessageRouter <IConsumeContext <TMessage> > router = routerConfigurator.FindOrCreate <TMessage>();

            var sink = new InstanceMessageSink <TMessage>(MultipleHandlerSelector.ForHandler(handler));

            UnsubscribeAction result = router.Connect(sink);

            UnsubscribeAction remove = configurator.SubscribedTo <TMessage>();

            return(() => result() && (router.SinkCount == 0) && remove());
        }
Esempio n. 9
0
        public UnsubscribeAction Connect(IInboundPipelineConfigurator configurator)
        {
            var routerConfigurator = new InboundMessageRouterConfigurator(configurator.Pipeline);

            MessageRouter <IConsumeContext <TMessage> > router = routerConfigurator.FindOrCreate <TMessage>();

            ISagaMessageSink <TSaga, TMessage> sink = CreateSink();

            UnsubscribeAction result = router.Connect(sink);

            UnsubscribeAction remove = configurator.SubscribedTo <TMessage>();

            return(() => result() && (router.SinkCount == 0) && remove());
        }
Esempio n. 10
0
        public UnsubscribeAction Connect <T>(IInboundPipelineConfigurator configurator, IConsumerFactory <T> factory)
            where T : class
        {
            var consumerFactory = factory as IConsumerFactory <TConsumer>;

            if (consumerFactory == null)
            {
                throw new ArgumentException("The consumer factory is of an invalid type: " +
                                            typeof(T).ToShortTypeName());
            }

            var sink = new ContextConsumerMessageSink <TConsumer, TMessage>(consumerFactory);

            return(configurator.Pipeline.ConnectToRouter(sink, () => configurator.SubscribedTo <TMessage>()));
        }
        public UnsubscribeAction Connect(IInboundPipelineConfigurator configurator)
        {
            ISagaMessageSink <TSaga, TMessage> sink = CreateSink();

            return(configurator.Pipeline.ConnectToRouter(sink, () => configurator.SubscribedTo <TMessage>()));
        }
        public ISubscriptionReference Connect(IInboundPipelineConfigurator configurator, IWorker worker)
        {
            IWorkerLoad <TMessage> workerLoad = worker.GetWorkerLoad <TMessage>();

            var handlerSink = new InstanceMessageSink <TMessage>(MultipleHandlerSelector.ForHandler(_handler));

            var sink = new WorkerMessageSink <TMessage>(workerLoad, handlerSink);

            UnsubscribeAction unsubscribeAction = configurator.Pipeline.ConnectToRouter(sink,
                                                                                        () => configurator.SubscribedTo <Distributed <TMessage> >());

            return(_referenceFactory(unsubscribeAction));
        }