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());
        }
Example #2
0
        public void when_null_added_as_message_broker_it_should_fail()
        {
            var configurator = new MessageRouterConfigurator();
            // ReSharper disable once AssignNullToNotNullAttribute - it's a test against null.
            Action sut = () => configurator.AddMessageBroker(configurator: null);

            sut.Should().Throw <ArgumentNullException>();
        }
Example #3
0
        public void when_message_broker_added_it_should_be_added_into_configuration()
        {
            var          sut        = new MessageRouterConfigurator();
            const string expectedId = "id";

            sut.AddMessageBroker(broker => broker.WithId(expectedId));
            sut.Configuration.Brokers.Single(broker => broker.Id.Equals(expectedId)).Should().NotBeNull("broker should be added");
        }
Example #4
0
        /// <summary>
        /// Provides the message router configuration.
        /// </summary>
        /// <param name="configurator">
        /// The message router configurator.
        /// </param>
        /// <returns>
        /// Message router configuration.
        /// </returns>
        /// <exception cref="ArgumentNullException">
        /// Configurator is not specified.
        /// </exception>
        public static MessageRouterConfiguration Configure([NotNull] Action <MessageRouterConfigurator> configurator)
        {
            if (configurator == null)
            {
                throw new ArgumentNullException(nameof(configurator));
            }

            var poezdConfigurator = new MessageRouterConfigurator();

            configurator(poezdConfigurator);
            return(poezdConfigurator.Configuration);
        }
        public BatchMessageRouter <TMessage, TBatchId> FindOrCreate <TMessage, TBatchId>()
            where TMessage : class, BatchedBy <TBatchId>
        {
            MessageRouterConfigurator configurator = MessageRouterConfigurator.For(_sink);

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

            var scope = new BatchMessageRouterConfiguratorScope <TMessage, TBatchId>();

            router.Inspect(scope);

            return(scope.Router ?? ConfigureRouter <TMessage, TBatchId>(router));
        }
Example #6
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());
        }