Ejemplo n.º 1
0
        protected virtual UnsubscribeAction Connect <TComponent, TMessage>(ISubscriberContext context)
            where TMessage : class
            where TComponent : class, Observes <TMessage, TComponent>, ISaga
        {
            MessageRouterConfigurator routerConfigurator = MessageRouterConfigurator.For(context.Pipeline);

            var router = routerConfigurator.FindOrCreate <TMessage>();

            var instance = (Observes <TMessage, TComponent>) FastActivator <TComponent> .Create(Guid.Empty);

            Expression <Func <TComponent, TMessage, bool> > selector = instance.GetBindExpression();

            var repository = context.Builder.GetInstance <ISagaRepository <TComponent> >();
            var policy     = new ExistingSagaPolicy <TComponent, TMessage>(x => false);
            var sink       = new PropertySagaMessageSink <TComponent, TMessage>(context, context.Data as IServiceBus, repository, policy, selector);

            if (sink == null)
            {
                throw new ConfigurationException("Could not build the message sink for " + typeof(TComponent).FullName);
            }

            var result = router.Connect(sink);

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

            return(() => result() && (router.SinkCount == 0) && remove());
        }
Ejemplo n.º 2
0
        protected virtual UnsubscribeAction Connect <TMessage>(ISubscriberContext context, Consumes <TMessage> .All consumer)
            where TMessage : class
        {
            var sink = new InstanceMessageSink <TMessage>(message => consumer.Consume);

            return(context.Pipeline.ConnectToRouter(sink, () => context.SubscribedTo <TMessage>()));
        }
        protected virtual UnsubscribeAction Connect <TComponent, TMessage>(ISubscriberContext context)
            where TMessage : class
            where TComponent : class, Consumes <TMessage> .Selected
        {
            var sink = new SelectedComponentMessageSink <TComponent, TMessage>(context);

            return(context.Pipeline.ConnectToRouter(sink, () => context.SubscribedTo <TMessage>()));
        }
Ejemplo n.º 4
0
        private UnsubscribeAction ConnectTo <TMessage>(DataEvent <TSaga, TMessage> eevent, IEnumerable <State> states)
            where TMessage : class
        {
            var factory = new SagaStateMachineMessageSinkFactory <TSaga, TMessage>(_context, _policyFactory);
            IPipelineSink <TMessage> sink = factory.Create(eevent, states);

            return(_context.Pipeline.ConnectToRouter(sink, () => _context.SubscribedTo <TMessage>()));
        }
Ejemplo n.º 5
0
        private UnsubscribeAction ConnectToSink <TSaga, TMessage>(ISubscriberContext context, ISagaWorker <TSaga> worker, DataEvent <TSaga, TMessage> eevent, IEnumerable <State> states)
            where TSaga : SagaStateMachine <TSaga>, ISaga
            where TMessage : class
        {
            var factory = new SagaStateMachineMessageSinkFactory <TSaga, TMessage>(context, _policyFactory);
            IPipelineSink <TMessage> sink = factory.Create(eevent, states);

            var workerSink = new SagaWorkerMessageSink <TSaga, TMessage>(worker, sink);

            return(context.Pipeline.ConnectToRouter(workerSink, () => context.SubscribedTo <Distributed <TMessage> >()));
        }
        protected virtual UnsubscribeAction Connect <TMessage>(ISubscriberContext context, Consumes <TMessage> .Selected consumer)
            where TMessage : class
        {
            var sink = new InstanceMessageSink <TMessage>(message =>
            {
                // rock it
                return(consumer.Accept(message) ? (Action <TMessage>)consumer.Consume : null);
            });

            return(context.Pipeline.ConnectToRouter(sink, () => context.SubscribedTo <TMessage>()));
        }
Ejemplo n.º 7
0
        protected virtual UnsubscribeAction ConnectWorker <TComponent, TMessage>(ISubscriberContext context, Consumes <Distributed <TMessage> > .Selected consumer)
            where TComponent : Consumes <Distributed <TMessage> > .Selected
            where TMessage : class
        {
            var sink = new WorkerMessageSink <Distributed <TMessage> >(message =>
            {
                // rock it
                return(consumer.Accept(message) ? (Action <Distributed <TMessage> >)consumer.Consume : null);
            });

            return(context.Pipeline.ConnectToRouter(sink, () => context.SubscribedTo <Distributed <TMessage> >()));
        }
Ejemplo n.º 8
0
        protected virtual UnsubscribeAction Connect <TMessage, TBatchId>(ISubscriberContext context, Consumes <Batch <TMessage, TBatchId> > .All consumer)
            where TMessage : class, BatchedBy <TBatchId>
        {
            var configurator = BatchMessageRouterConfigurator.For(context.Pipeline);

            var router = configurator.FindOrCreate <TMessage, TBatchId>();

            var result = router.Connect(new InstanceMessageSink <Batch <TMessage, TBatchId> >(message => consumer.Consume));

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

            return(() => result() && (router.SinkCount == 0) && remove());
        }
Ejemplo n.º 9
0
        protected virtual UnsubscribeAction Connect <TMessage, TKey>(ISubscriberContext context, Consumes <TMessage> .For <TKey> consumer)
            where TMessage : class, CorrelatedBy <TKey>
        {
            var correlatedConfigurator = CorrelatedMessageRouterConfigurator.For(context.Pipeline);

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

            UnsubscribeAction result = router.Connect(consumer.CorrelationId, new InstanceMessageSink <TMessage>(message => consumer.Consume));

            UnsubscribeAction remove = context.SubscribedTo <TMessage, TKey>(consumer.CorrelationId);

            return(() => result() && remove());
        }
Ejemplo n.º 10
0
        protected virtual UnsubscribeAction Connect <TComponent, TMessage>(ISubscriberContext context)
            where TMessage : class, CorrelatedBy <Guid>
            where TComponent : class, Orchestrates <TMessage>, ISaga
        {
            MessageRouterConfigurator routerConfigurator = MessageRouterConfigurator.For(context.Pipeline);

            var router = routerConfigurator.FindOrCreate <TMessage>();

            var repository = context.Builder.GetInstance <ISagaRepository <TComponent> >();
            var policy     = new ExistingSagaPolicy <TComponent, TMessage>(x => false);
            var sink       = new CorrelatedSagaMessageSink <TComponent, TMessage>(context, context.Data as IServiceBus, repository, policy);

            if (sink == null)
            {
                throw new ConfigurationException("Could not build the message sink for " + typeof(TComponent).FullName);
            }

            var result = router.Connect(sink);

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

            return(() => result() && (router.SinkCount == 0) && remove());
        }