title: How to set the replyTo with JmsTemplate?
body: <p>I have a consumer consumes a message do some transformation and create a new Pojo and pass to a producer.
  The producer sends the message in queue using the JmsTemplate.
  The producer should set the headers of the original message like (JMSType, JMSCorrelationID, JMSExpiration, JMSDeliveryMode) to the new message to send.
  But the producer should to change the replyTo Destination of the original message.
  I haven't found a way to create a Destination and set to the JMSReplyTo.
  Some have an idea how I can do that?</p>
  
  <p>Maybe the JmsTemplate is not the correct class to do that.</p>
  
  <pre><code>public class Producer {
  
      private final JmsTemplate jmsTemplate;
  
      @Value("${jms-destination}")
      private String destination;
  
      public Producer(@Autowired JmsTemplate jmsTemplate) {
          this.jmsTemplate = jmsTemplate;
      }
  
      public void send(final MessageHeaders headers, final Pojo pojo) {
          Validate.notNull(order);
  
          jmsTemplate.convertAndSend(destination, pojo, (message) -&gt; {
            final Destination replyToDestination = ???;
            message.setJMSReplyTo(replyToDestination);
  
            message.setJMSType((String) headers.get(JmsHeaders.TYPE));
            message.setJMSCorrelationID((String) headers.get(JmsHeaders.CORRELATION_ID));
            message.setJMSExpiration((long) headers.get(JmsHeaders.EXPIRATION));
            message.setJMSDeliveryMode((int) headers.get(JmsHeaders.DELIVERY_MODE));
            return message;
        });
  
      }
  }
  </code></pre>
  
  <p>I have found only this way to do, but I don't like and I don't sure that this introduce side effect:</p>
  
  <pre><code>public class Producer {
  
      private final JmsTemplate jmsTemplate;
  
      @Value("${jms-destination}")
      private String destination;
  
      @Value("${jms-replyTo}")
      private String replyTo;
  
      public Producer(@Autowired JmsTemplate jmsTemplate) {
          this.jmsTemplate = jmsTemplate;
      }
  
      public void send(final MessageHeaders headers, Pojo pojo) {
          Validate.notNull(order);
  
          jmsTemplate.convertAndSend(destination, order, (message) -&gt; {
            final Destination replyToDestination = buildReplyTo();
            message.setJMSReplyTo(replyToDestination);
  
            message.setJMSType((String) headers.get(JmsHeaders.TYPE));
            message.setJMSCorrelationID((String) headers.get(JmsHeaders.CORRELATION_ID));
            message.setJMSExpiration((long) headers.get(JmsHeaders.EXPIRATION));
            message.setJMSDeliveryMode((int) headers.get(JmsHeaders.DELIVERY_MODE));
            return message;
        });
  
      }
  
      private Destination buildReplyTo() throws JMSException {
        final Session session = jmsTemplate.getConnectionFactory().createConnection()
            .createSession(false, Session.AUTO_ACKNOWLEDGE);
        final Destination queue =
            jmsTemplate.getDestinationResolver().resolveDestinationName(session, replyTo, false);
        return queue;
      }
  
  }
  </code></pre>