title: What is a JmsTemplate callback in Spring JMS?
body: <p>this is my first time with <strong>Spring JMS</strong> (and with JMS in general) and I have some doubts related the concept of the <strong>JmsTemplate</strong> callback.</p>
  
  <p>I know that the <strong>JmsTemplate</strong> is a class provided from Spring to:</p>
  
  <ul>
  <li>Reduces boilerplate code.</li>
  <li>Manages resources transparently.</li>
  <li>Converts checked exceptions to runtime equivalents.</li>
  <li>Provides convenience methods and callbacks.</li>
  </ul>
  
  <p>and that it is used for message production and synchronous message reception. It simplifies the use of JMS since it handles the creation and release of resources when sending or synchronously receiving messages.</p>
  
  <p>Reading the Spring official documentation (here: <a href="http://docs.spring.io/spring/docs/current/spring-framework-reference/html/jms.html">http://docs.spring.io/spring/docs/current/spring-framework-reference/html/jms.html</a>) I found:</p>
  
  <blockquote>
    <p>Code that uses the JmsTemplate only needs to implement callback
    interfaces giving them a clearly defined high level contract. The
    MessageCreator callback interface creates a message given a Session
    provided by the calling code in JmsTemplate.</p>
  </blockquote>
  
  <p>This is not clear for me. What exactly are these callback? </p>
  
  <p>At the beginning I thought that a callback are a method provided from the <strong>JmsTemplate</strong> but reading here it seems something more similar to an interface that I have to implement. How it works?</p>
  
  <p>I also found this example:</p>
  
  <p><strong>SENDING A POJO THROUGHT JMS (using the JmsTemplate):</strong></p>
  
  <pre><code>public class JmsOrderManager implements OrderManager {
      @Autowired JmsTemplate jmsTemplate;
      @Autowired Destination orderQueue;
  
      public void placeOrder(Order order) {
          String stringMessage = "New order " + order.getNumber();
          jmsTemplate.convertAndSend("messageQueue", stringMessage );
          // use destination resolver and message converter
          jmsTemplate.convertAndSend(orderQueue, order); // use message converter
          jmsTemplate.convertAndSend(order); // use converter and default destination
      }
  }
  </code></pre>
  
  <p>I thought that the <strong>convertAndSend()</strong> method is a JmsTemplate <strong>callback</strong> but probably this assertion is not correct. </p>
  
  <p>Can you explain me what exactly is a JmsTemplate callback?</p>