Example #1
0
        public async Task TestCorrelationNotCopiedFromRequestMessgeIdIfAlreadySetByHandler()
        {
            IMessage message          = Message.Create("test");
            var      inputChannel     = new DirectChannel(provider.GetService <IApplicationContext>());
            var      outputChannel    = new QueueChannel(provider.GetService <IApplicationContext>(), 1);
            var      serviceActivator = new ServiceActivatingHandler(provider.GetService <IApplicationContext>(), new TestBeanCreateMessage());

            serviceActivator.OutputChannel = outputChannel;
            var endpoint = new EventDrivenConsumerEndpoint(provider.GetService <IApplicationContext>(), inputChannel, serviceActivator);
            await endpoint.Start();

            Assert.True(inputChannel.Send(message));
            var reply    = outputChannel.Receive(0);
            var accessor = new IntegrationMessageHeaderAccessor(reply);

            Assert.Equal("456-XYZ", accessor.GetCorrelationId());
        }
Example #2
0
        protected override IMessageHandler CreateHandler(object service, MethodInfo method, List <Attribute> attributes)
        {
            AbstractReplyProducingMessageHandler serviceActivator;

            if (method.GetCustomAttribute <ServiceAttribute>() != null)
            {
                // Service Attribute usage
                var target = ResolveTargetServiceFromMethodWithServiceAnnotation(method);
                serviceActivator = ExtractTypeIfPossible <AbstractReplyProducingMessageHandler>(target);
                if (serviceActivator == null)
                {
                    if (target is IMessageHandler handler)
                    {
                        /*
                         * Return a reply-producing message handler so that we still get 'produced no reply' messages
                         * and the super class will inject the advice chain to advise the handler method if needed.
                         */
                        return(new ReplyProducingMessageHandlerWrapper(ApplicationContext, handler));
                    }
                    else
                    {
                        serviceActivator = new ServiceActivatingHandler(ApplicationContext, target, method);
                    }
                }
                else
                {
                    CheckMessageHandlerAttributes(ResolveTargetServiceName(method), attributes);
                    return((IMessageHandler)target);
                }
            }
            else
            {
                serviceActivator = new ServiceActivatingHandler(ApplicationContext, service, method);
            }

            var requiresReply = MessagingAttributeUtils.ResolveAttribute <string>(attributes, "RequiresReply");

            if (!string.IsNullOrEmpty(requiresReply))
            {
                serviceActivator.RequiresReply = bool.Parse(ApplicationContext.ResolveEmbeddedValue(requiresReply));
            }

            SetOutputChannelIfPresent(attributes, serviceActivator);
            return(serviceActivator);
        }
Example #3
0
        public async Task TestCorrelationNotPassedFromRequestHeaderIfAlreadySetByHandler()
        {
            object correlationId    = "123-ABC";
            var    message          = Support.IntegrationMessageBuilder.WithPayload("test").SetCorrelationId(correlationId).Build();
            var    inputChannel     = new DirectChannel(provider.GetService <IApplicationContext>());
            var    outputChannel    = new QueueChannel(provider.GetService <IApplicationContext>(), 1);
            var    serviceActivator = new ServiceActivatingHandler(provider.GetService <IApplicationContext>(), new TestBeanCreateMessage());

            serviceActivator.OutputChannel = outputChannel;
            var endpoint = new EventDrivenConsumerEndpoint(provider.GetService <IApplicationContext>(), inputChannel, serviceActivator);
            await endpoint.Start();

            Assert.True(inputChannel.Send(message));
            var reply    = outputChannel.Receive(0);
            var accessor = new IntegrationMessageHeaderAccessor(reply);

            Assert.Equal("456-XYZ", accessor.GetCorrelationId());
        }
Example #4
0
        public async Task TestCorrelationIdPassedIfAvailable()
        {
            object correlationId    = "123-ABC";
            var    message          = Support.MessageBuilder.WithPayload("test").SetCorrelationId(correlationId).Build();
            var    inputChannel     = new DirectChannel(provider);
            var    outputChannel    = new QueueChannel(provider, 1);
            var    serviceActivator = new ServiceActivatingHandler(provider, new TestBeanUpperCase());

            serviceActivator.OutputChannel = outputChannel;
            var endpoint = new EventDrivenConsumerEndpoint(provider, inputChannel, serviceActivator);
            await endpoint.Start();

            Assert.True(inputChannel.Send(message));
            var reply    = outputChannel.Receive(0);
            var accessor = new IntegrationMessageHeaderAccessor(reply);

            Assert.Equal(correlationId, accessor.GetCorrelationId());
        }
Example #5
0
        public void OutputChannelTakesPrecedence()
        {
            QueueChannel             channel1 = new QueueChannel(1);
            QueueChannel             channel2 = new QueueChannel(1);
            ServiceActivatingHandler endpoint = CreateEndpoint();

            endpoint.OutputChannel = channel1;
            IMessage message = MessageBuilder.WithPayload("foo").SetReplyChannel(channel2).Build();

            endpoint.HandleMessage(message);
            IMessage reply1 = channel1.Receive(TimeSpan.Zero);

            Assert.IsNotNull(reply1);
            Assert.That(reply1.Payload, Is.EqualTo("FOO"));
            IMessage reply2 = channel2.Receive(TimeSpan.Zero);

            Assert.IsNull(reply2);
        }
Example #6
0
        public void ReturnAddressHeaderWithChannelName()
        {
            QueueChannel channel = new QueueChannel(1);

            channel.ObjectName = "testChannel";
            TestChannelResolver channelResolver = new TestChannelResolver();

            channelResolver.AddChannel(channel);
            ServiceActivatingHandler endpoint = CreateEndpoint();

            endpoint.ChannelResolver = channelResolver;
            IMessage message = MessageBuilder.WithPayload("foo")
                               .SetReplyChannelName("testChannel").Build();

            endpoint.HandleMessage(message);
            IMessage reply = channel.Receive(TimeSpan.Zero);

            Assert.IsNotNull(reply);
            Assert.That(reply.Payload, Is.EqualTo("FOO"));
        }
Example #7
0
        private ServiceActivatingHandler CreateConsumer(IMessageProcessor processor)
        {
            var handler = new ServiceActivatingHandler(provider.GetService <IApplicationContext>(), processor);

            return(handler);
        }
Example #8
0
        private ServiceActivatingHandler CreateConsumer(IMessageProcessor processor)
        {
            var handler = new ServiceActivatingHandler(provider, processor);

            return(handler);
        }