this is my first time with Spring JMS (and with JMS in general) and I have some doubts related the concept of the JmsTemplate callback.
I know that the JmsTemplate is a class provided from Spring to:
- Reduces boilerplate code.
- Manages resources transparently.
- Converts checked exceptions to runtime equivalents.
- Provides convenience methods and callbacks.
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.
Reading the Spring official documentation (here: http://docs.spring.io/spring/docs/current/spring-framework-reference/html/jms.html) I found:
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.
This is not clear for me. What exactly are these callback?
At the beginning I thought that a callback are a method provided from the JmsTemplate but reading here it seems something more similar to an interface that I have to implement. How it works?
I also found this example:
SENDING A POJO THROUGHT JMS (using the JmsTemplate):
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
}
}
I thought that the convertAndSend() method is a JmsTemplate callback but probably this assertion is not correct.
Can you explain me what exactly is a JmsTemplate callback?