MessageCreator is a Spring JMS callback that creates the Message passed to JmsTemplate.send(). JmsTemplate handles the sending work; the callback focuses on constructing the message. section 9.1.2
Send an order
To send an order, implement createMessage(Session session) and return session.createObjectMessage(order). Because MessageCreator has one method, the same callback can be written as a lambda: session -> session.createObjectMessage(order). section 9.1.2
@Override
public void sendOrder(TacoOrder order) {
jms.send(session -> session.createObjectMessage(order));
}
The lambda creates an ObjectMessage from the order; send() sends it to the configured default destination. section 9.1.2
Use send() with MessageCreator when you want to construct the JMS message yourself. Use convertAndSend() when you want JmsTemplate to convert an object into a message instead. Either approach can target a default destination, a Destination object, or a destination name. section 9.1.2
