title: How to correlate request & reply when using raw (not using Gateway) Spring Integration?
body: <p>I am learning about Spring-Integration and have a basic understanding about Gateway and Service-Activators. I love the concept of Gateway. Spring Integration generates the proxy for gateway at run-time. This proxy hides all the messaging details from the consumer of the gateway. In addition, the generated proxy might also be co-relating request and reply. </p>
  
  <p>With the objective of learning, I set out to implement request and reply correlation using raw Spring Integration features and not using Gateway. I am able to set the correlation identifier in the request header, but not able to specify correlation identifier while receiving reply for the channel. The following (at the end of the question) is the code snippet for the same. Also how does the correlation stuff works against a message broker (e.g. RabbitMQ)? Does RabbitMQ provides an ability to retrieve a message with a specific header (correlation identifier) in it?</p>
  
  <pre><code>public class RemoteProxyCalculatorService implements CalculatorService
  {
      public int Square(int n) 
      {
          UUID uuid = SendRequest(n, "squareRequestChannel");
          int squareOfn = ReceiveReply("squareReplyChannel", uuid);
          return squareOfn;
      }
  
      private &lt;T&gt; UUID SendRequest(T payload, String requestChannel)
      {
          UUID requestID = UUID.randomUUID();
          Message&lt;T&gt; inputMessage = MessageBuilder.withPayload(payload)
                  .setCorrelationId(requestID)
                  .build();
  
          MessageChannel channel = (MessageChannel)context.getBean(requestChannel, MessageChannel.class);
          channel.send(inputMessage);
          return requestID;
      }
  
      @SuppressWarnings("unchecked")
      private &lt;T&gt; T ReceiveReply(String replyChannel, UUID requestID)
      {
          //How to consume requestID so as to receive only the reply related to the request posted by this thread
          PollableChannel channel = (PollableChannel)context.getBean(replyChannel);
          Message&lt;?&gt; groupMessage = channel.receive();
          return (T)groupMessage.getPayload();
      }
  
      private ClassPathXmlApplicationContext context;
  }
  </code></pre>
  
  <p>Thanks.</p>