title: How to send correlation id, into message, from sender and retrieval from receive into message header with Rabbit MQ by java
body: <p>I have used Rabbit MQ to send and receive a JSON message.<br>
  I have implemented an application using the RabbitTemplate instance with convertAndSend method to send a message to the exchange as below:
  <a href="https://i.stack.imgur.com/6s2jZ.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/6s2jZ.png" alt="enter image description here"></a></p>
  
  <pre><code>rabbitTemplate.convertAndSend(exchangeNameOut, message.getString(PERSISTENCE_MESSAGE_ROUTING_KEY),
                      message.getString(PERSISTENCE_MESSAGE_BODY), new CorrelationData(""+analyticRuntime.getId()));
  </code></pre>
  
  <p>While to retrieval a message, side receiver, I have implemented the followed method:</p>
  
  <pre><code>        @RabbitListener(queues = "${rabbit.queue.mail.name}",containerFactory = "rabbitListenerContainerFactory")
       public void processMailMessage(Message message) {
          log.info("ENTER [processMailMessage]  ");
  
          Mail mail;
  
              JSONObject messageBody = new JSONObject(new String(message.getBody()));
  
              String asset = "" + messageBody.get(Constants.PERSISTENCE_MESSAGE_ASSET_ID_KEY);
  
              String body = "" + messageBody.get(Constants.PERSISTENCE_MESSAGE_EVENT_KEY);
  
              String alarms = "";
              log.info("[processMailMessage] message.getMessageProperties().getCorrelationId() : " + message.getMessageProperties().getCorrelationId()";
  }
  </code></pre>
  
  <p>The question is:</p>
  
  <ul>
  <li>Why the message.getMessageProperties().getCorrelationId() is NULL ?
  Into the send method I have inserted the correlation.</li>
  <li>Correlation Id is the same thing of Correlation Data that I have inserted into convertAndSend method ?</li>
  <li>How can I retrieval the correlation Id into receiver method ?</li>
  </ul>
  
  <p>Thanks</p>