public void TestCorrelationIdPassedIfAvailable()
 {
     object correlationId = "123-ABC";
     IMessage message = MessageBuilder.WithPayload("test").SetCorrelationId(correlationId).Build();
     DirectChannel inputChannel = new DirectChannel();
     QueueChannel outputChannel = new QueueChannel(1);
     ServiceActivatingHandler serviceActivator = new ServiceActivatingHandler(new TestBean(), "UpperCase");
     serviceActivator.OutputChannel = outputChannel;
     EventDrivenConsumer endpoint = new EventDrivenConsumer(inputChannel, serviceActivator);
     endpoint.Start();
     Assert.IsTrue(inputChannel.Send(message));
     IMessage reply = outputChannel.Receive(TimeSpan.Zero);
     Assert.That(reply.Headers.CorrelationId, Is.EqualTo(correlationId));
 }
 private void ConfigureChain()
 {
     DirectChannel channel = null;
     IList<IMessageHandler> handlers = _handlers;
     for(int i = 0; i < handlers.Count; i++) {
         bool first = (i == 0);
         bool last = (i == handlers.Count - 1);
         IMessageHandler handler = handlers[i];
         if(!first) {
             EventDrivenConsumer consumer = new EventDrivenConsumer(channel, handler);
             consumer.Start();
         }
         if(!last) {
             if(!(handler is AbstractReplyProducingMessageHandler))
                 throw new ArgumentException("All handlers except for the last one in the chain must implement " + typeof(AbstractReplyProducingMessageHandler).Name);
             channel = new DirectChannel();
             channel.ObjectName = "_" + this + ".channel#" + i;
             ((AbstractReplyProducingMessageHandler)handler).OutputChannel = channel;
         }
         else if(handler is AbstractReplyProducingMessageHandler) {
             IMessageChannel replyChannel = (_outputChannel != null) ? _outputChannel : new ReplyForwardingMessageChannel(this);
             ((AbstractReplyProducingMessageHandler)handler).OutputChannel = replyChannel;
         }
         else {
             if(_outputChannel == null)
                 throw new ArgumentException("An output channel was provided, but the final handler in the chain is not an "
                         + "instance of [" + typeof(AbstractReplyProducingMessageHandler).Name + "]");
         }
     }
 }
 public void TestCorrelationNotCopiedFromRequestMessgeIdIfAlreadySetByHandler()
 {
     IMessage message = new StringMessage("test");
     DirectChannel inputChannel = new DirectChannel();
     QueueChannel outputChannel = new QueueChannel(1);
     ServiceActivatingHandler serviceActivator = new ServiceActivatingHandler(new TestBean(), "CreateMessage");
     serviceActivator.OutputChannel = outputChannel;
     EventDrivenConsumer endpoint = new EventDrivenConsumer(inputChannel, serviceActivator);
     endpoint.Start();
     Assert.IsTrue(inputChannel.Send(message));
     IMessage reply = outputChannel.Receive(TimeSpan.Zero);
     Assert.That(reply.Headers.CorrelationId, Is.EqualTo("456-XYZ"));
 }