Exemple #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());
        }
        public bool Inspect <TMessage, TKey>(CorrelatedMessageRouter <TMessage, TKey> sink)
            where TMessage : class, CorrelatedBy <TKey>
        {
            Append(string.Format("Correlated by {1} ({0})", typeof(TMessage).Name, typeof(TKey).Name));

            return(true);
        }
        public bool Inspect <T, TMessage, TKey>(CorrelatedMessageRouter <T, TMessage, TKey> sink)
            where TMessage : class, CorrelatedBy <TKey>
            where T : class, IMessageContext <TMessage>
        {
            Append(string.Format("Correlated by {1} ({0})", GetMessageName <TMessage>(), typeof(TKey).ToFriendlyName()));

            return(true);
        }
Exemple #4
0
        public bool Inspect <TRoutedMessage, TRoutedKey>(CorrelatedMessageRouter <TRoutedMessage, TRoutedKey> element)
            where TRoutedMessage : class, CorrelatedBy <TRoutedKey>
        {
            if (typeof(TRoutedMessage) == typeof(TMessage))
            {
                Router = element.TranslateTo <CorrelatedMessageRouter <TMessage, TKey> >();

                return(false);
            }

            return(true);
        }
        public bool Inspect <T, TM, TK>(CorrelatedMessageRouter <T, TM, TK> router)
            where T : class, IMessageContext <TM>
            where TM : class, ICorrelatedBy <TK>
        {
            if (typeof(T) == typeof(IConsumeContext <TMessage>) && typeof(TM) == typeof(TMessage) &&
                typeof(TK) == typeof(TKey))
            {
                Router = router.TranslateTo <CorrelatedMessageRouter <IConsumeContext <TMessage>, TMessage, TKey> >();

                return(false);
            }

            return(true);
        }
Exemple #6
0
        private static CorrelatedMessageRouter <TMessage, TKey> ConfigureRouter <TMessage, TKey>(MessageRouter <TMessage> messageRouter)
            where TMessage : class, CorrelatedBy <TKey>
        {
            if (messageRouter == null)
            {
                throw new PipelineException("The base object router was not found");
            }

            var router = new CorrelatedMessageRouter <TMessage, TKey>();

            messageRouter.Connect(router);

            return(router);
        }
        public static UnsubscribeAction ConnectEndpoint <TMessage, TKey>(this IOutboundMessagePipeline pipeline,
                                                                         TKey correlationId,
                                                                         IEndpoint endpoint)
            where TMessage : class, ICorrelatedBy <TKey>
        {
            var correlatedConfigurator = new OutboundCorrelatedMessageRouterConfigurator(pipeline);

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

            UnsubscribeAction result = router.Connect(correlationId, new EndpointMessageSink <TMessage>(endpoint));

            return(result);
        }
Exemple #8
0
        static CorrelatedMessageRouter <IConsumeContext <TMessage>, TMessage, TKey> ConfigureRouter <TMessage, TKey>(
            MessageRouter <IConsumeContext <TMessage> > inputRouter)
            where TMessage : class, CorrelatedBy <TKey>
        {
            if (inputRouter == null)
            {
                throw new PipelineException("The input router was not found");
            }

            var outputRouter = new CorrelatedMessageRouter <IConsumeContext <TMessage>, TMessage, TKey>();

            inputRouter.Connect(outputRouter);

            return(outputRouter);
        }