liveBook · Manning

convertAndSend()

As explained in Spring in Action, Sixth Edition

convertAndSend() is a JmsTemplate method that converts an application object into a JMS message and sends it.

`convertAndSend()` lets `JmsTemplate` send an application object as a JMS message. Unlike `send()`, it does not require you to create the message with a `MessageCreator`: a `MessageConverter` handles that step. section 9.1.2

Send an order to a named queue

`jms.convertAndSend("tacocloud.order.queue", order);` sends the `TacoOrder` object without manually creating a JMS `Message`. section 9.1.2

An overload can instead use a configured default destination or a `Destination` object. To change the converted message before sending it, pass a `MessagePostProcessor`; for example, it can set the `X_ORDER_SOURCE` property to `WEB`. section 9.1.2

How Spring in Action, Sixth Edition covers it

How deep it goes
Works through destination overloads, automatic conversion, and post-processing rather than manual message creation.
Examples
Uses a TacoOrder sent to a named queue and a post-processor that adds a JMS property.
What it assumes
Introduces automatic conversion by contrasting it with send(), while assuming an available JmsTemplate and destination.
What you can do after
Apply it via JmsTemplate to send an order object and optionally customize its message.
How it connects
Connects JmsTemplate, MessageConverter, MessagePostProcessor, JMS destinations, and send().

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Spring in Action, Sixth Edition. The section links point to the parts of the book it draws on.