If you want to use dynamic destination creation, you must specify the type of JMS destination to create, using the "pubSubDomain" property. For other operations, this is not necessary. Point-to-Point (Queues) is the default domain.
Default settings for JMS Sessions are "not transacted" and "auto-acknowledge". As defined by the Jakarta EE specification, the transaction and acknowledgement parameters are ignored when a JMS Session is created inside an active transaction, no matter if a JTA transaction or a Spring-managed transaction. To configure them for native JMS usage, specify appropriate values for the "sessionTransacted" and "sessionAcknowledgeMode" bean properties.
This template uses a
org.
and a org.
as default strategies for resolving a destination name or converting a message,
respectively. These defaults can be overridden through the "destinationResolver"
and "messageConverter" bean properties.
NOTE: The ConnectionFactory used with this template should
return pooled Connections (or a single shared Connection) as well as pooled
Sessions and MessageProducers. Otherwise, performance of ad-hoc JMS operations
is going to suffer. The simplest option is to use the Spring-provided
org. as a
decorator for your target ConnectionFactory, reusing a single
JMS Connection in a thread-safe fashion; this is often good enough for the
purpose of sending messages via this template. In a Jakarta EE environment,
make sure that the ConnectionFactory is obtained from the
application's environment naming context via JNDI; application servers
typically expose pooled, transaction-aware factories there.
setConnectionFactory, setPubSubDomain, setDestinationResolver, setMessageConverter, jakarta.jms.MessageProducer , jakarta.jms.MessageConsumer
| Modifier and Type | Class and Description |
|---|---|
| private class | JmsTemplate.
ResourceFactory implementation that delegates to this template's protected callback methods. |
| private abstract static class |
| Modifier and Type | Field and Description |
|---|---|
| private Object | |
| private long | |
| private int | |
| private boolean | |
| private MessageConverter | |
| private boolean | |
| private boolean | |
| private static final boolean | |
| private ObservationRegistry | |
| private int | |
| private boolean | |
| private long | |
| private long | |
| private final JmsTemplate. | transactionalResourceFactory
Internal ResourceFactory adapter for interacting with ConnectionFactoryUtils. |
| Access | Constructor and Description |
|---|---|
| public | |
| public | JmsTemplate(ConnectionFactory
the ConnectionFactory to obtain Connections from connectionFactory)Create a new JmsTemplate, given a ConnectionFactory. |
| Modifier and Type | Method and Description |
|---|---|
| public <T> T | browse(BrowserCallback<T>
callback object that exposes the session/browser pair action)Implements org. Browse messages in the default JMS queue. |
| public <T> T | browse(Queue
the queue to browse queue, BrowserCallback<T> callback object that exposes the session/browser pair action)Implements org. Browse messages in a JMS queue. |
| public <T> T | browse(String
the name of the queue to browse
(to be resolved to an actual destination by a DestinationResolver) queueName, BrowserCallback<T> callback object that exposes the session/browser pair action)Implements org. Browse messages in a JMS queue. |
| public <T> T | browseSelected(String
the JMS message selector expression (or messageSelector, BrowserCallback<T> null if none).
See the JMS specification for a detailed definition of selector expressions.callback object that exposes the session/browser pair action)Implements org. Browse selected messages in a JMS queue. |
| public <T> T | browseSelected(final Queue
the queue to browse queue, final String the JMS message selector expression (or messageSelector, final BrowserCallback<T> null if none).
See the JMS specification for a detailed definition of selector expressions.callback object that exposes the session/browser pair action)Implements org. Browse selected messages in a JMS queue. |
| public <T> T | browseSelected(final String
the name of the queue to browse
(to be resolved to an actual destination by a DestinationResolver) queueName, final String the JMS message selector expression (or messageSelector, final BrowserCallback<T> null if none).
See the JMS specification for a detailed definition of selector expressions.callback object that exposes the session/browser pair action)Implements org. Browse selected messages in a JMS queue. |
| public void | convertAndSend(Object
the object to convert to a message message)Implements org. Send the given object to the default destination, converting the object to a JMS message with a configured MessageConverter. |
| public void | convertAndSend(Destination
the destination to send this message to destination, final Object the object to convert to a message message)Implements org. Send the given object to the specified destination, converting the object to a JMS message with a configured MessageConverter. |
| public void | convertAndSend(String
the name of the destination to send this message to
(to be resolved to an actual destination by a DestinationResolver) destinationName, final Object the object to convert to a message message)Implements org. Send the given object to the specified destination, converting the object to a JMS message with a configured MessageConverter. |
| public void | convertAndSend(Object
the object to convert to a message message, MessagePostProcessor the callback to modify the message postProcessor)Implements org. Send the given object to the default destination, converting the object to a JMS message with a configured MessageConverter. |
| public void | convertAndSend(Destination
the destination to send this message to destination, final Object the object to convert to a message message, final MessagePostProcessor the callback to modify the message postProcessor)Implements org. Send the given object to the specified destination, converting the object to a JMS message with a configured MessageConverter. |
| public void | convertAndSend(String
the name of the destination to send this message to
(to be resolved to an actual destination by a DestinationResolver) destinationName, final Object the object to convert to a message. message, final MessagePostProcessor the callback to modify the message postProcessor)Implements org. Send the given object to the specified destination, converting the object to a JMS message with a configured MessageConverter. |
| protected QueueBrowser | Returns: the new JMS QueueBrowserthe JMS Session to create a QueueBrowser for session, Queue the JMS Queue to create a QueueBrowser for queue, String the message selector for this consumer (can be messageSelector)null)Create a JMS MessageProducer for the given Session and Destination, configuring it to disable message ids and/or timestamps (if necessary). |
| protected MessageConsumer | Returns: the new JMS MessageConsumerthe JMS Session to create a MessageConsumer for session, Destination the JMS Destination to create a MessageConsumer for destination, String the message selector for this consumer (can be messageSelector)null)Create a JMS MessageConsumer for the given Session and Destination. |
| protected MessageProducer | Returns: the new JMS MessageProducerthe JMS Session to create a MessageProducer for session, Destination the JMS Destination to create a MessageProducer for destination)Create a JMS MessageProducer for the given Session and Destination, configuring it to disable message ids and/or timestamps (if necessary). |
| protected Object | Returns: the content of the message, ornull if nonethe JMS Message to convert (can be message)null)Extract the content from the given JMS message. |
| protected MessageProducer | Returns: the new JMS MessageProducerthe JMS Session to create a MessageProducer for session, Destination the JMS Destination to create a MessageProducer for destination)Create a raw JMS MessageProducer for the given Session and Destination. |
| protected Message | Returns: the JMS Message received, ornull if nonethe JMS Session to operate on session, Destination the JMS Destination to receive from destination, String the message selector for this consumer (can be messageSelector)null)Receive a JMS message. |
| protected Message | Returns: the JMS Message received, ornull if nonethe JMS Session to operate on session, MessageConsumer the JMS MessageConsumer to receive with consumer)Actually receive a JMS message. |
| protected void | doSend(Session
the JMS Session to operate on session, Destination the JMS Destination to send to destination, MessageCreator callback to create a JMS Message messageCreator)Send the given JMS message. |
| protected void | doSend(MessageProducer
the JMS MessageProducer to send with producer, Message the JMS Message to send message)Actually send the given JMS message. |
| protected Message | doSendAndReceive(Session session, Destination destination, MessageCreator messageCreator)
Send a request message to the given |
| public <T> T | execute(SessionCallback<T>
callback object that exposes the session action)Implements org. Execute the action specified by the given action object within a JMS Session. |
| public <T> T | Returns: the result object from working with the Sessioncallback object that exposes the Session action, boolean whether to start the Connection startConnection)Execute the action specified by the given action object within a JMS Session. |
| public <T> T | execute(ProducerCallback<T>
callback object that exposes the session/producer pair action)Implements org. Send messages to the default JMS destination (or one specified for each send operation). |
| public <T> T | execute(final Destination
the destination to send messages to destination, final ProducerCallback<T> callback object that exposes the session/producer pair action)Implements org. Send messages to a JMS destination. |
| public <T> T | execute(final String
the name of the destination to send messages to
(to be resolved to an actual destination by a DestinationResolver) destinationName, final ProducerCallback<T> callback object that exposes the session/producer pair action)Implements org. Send messages to a JMS destination. |
| private <T> T | executeLocal(SessionCallback<T> action, boolean startConnection)
A variant of |
| protected Connection | Returns: an appropriate Connection fetched from the holder, ornull if none foundthe JmsResourceHolder holder)Fetch an appropriate Connection from the given JmsResourceHolder. |
| public Destination | getDefaultDestination()
Return the destination to be used on send/receive operations that do not have a destination parameter. |
| public String | getDefaultDestinationName()
Return the destination name to be used on send/receive operations that do not have a destination parameter. |
| private Queue | |
| public long | |
| public int | |
| public MessageConverter | |
| public int | |
| public long | |
| private String | |
| private MessageConverter | |
| protected Session | Returns: an appropriate Session fetched from the holder, ornull if none foundthe JmsResourceHolder holder)Fetch an appropriate Session from the given JmsResourceHolder. |
| public long | |
| protected void | initDefaultStrategies()
Initialize the default implementations for the template's strategies: DynamicDestinationResolver and SimpleMessageConverter. |
| public boolean | Returns: true if overriding default values of QOS parameters (deliveryMode, priority, and timeToLive)If "true", then the values of deliveryMode, priority, and timeToLive will be used when sending a message. |
| public boolean | |
| public boolean | |
| public boolean | isPubSubNoLocal()
Return whether to inhibit the delivery of messages published by its own connection. |
| protected boolean | Returns: whether the given Session is locally transactedthe Session to check session)Check whether the given Session is locally transacted, that is, whether its transaction is managed by this listener container's Session handling and not by an external transaction coordinator. |
| public Message | receive()
Implements org. Receive a message synchronously from the default destination, but only wait up to a specified time for delivery. |
| public Message | receive(Destination
the destination to receive a message from destination)Implements org. Receive a message synchronously from the specified destination, but only wait up to a specified time for delivery. |
| public Message | receive(String
the name of the destination to send this message to
(to be resolved to an actual destination by a DestinationResolver) destinationName)Implements org. Receive a message synchronously from the specified destination, but only wait up to a specified time for delivery. |
| public Object | receiveAndConvert()
Implements org. Receive a message synchronously from the default destination, but only wait up to a specified time for delivery. |
| public Object | receiveAndConvert(Destination
the destination to receive a message from destination)Implements org. Receive a message synchronously from the specified destination, but only wait up to a specified time for delivery. |
| public Object | receiveAndConvert(String
the name of the destination to send this message to
(to be resolved to an actual destination by a DestinationResolver) destinationName)Implements org. Receive a message synchronously from the specified destination, but only wait up to a specified time for delivery. |
| public Message | receiveSelected(String
the JMS message selector expression (or messageSelector)null if none).
See the JMS specification for a detailed definition of selector expressions.Implements org. Receive a message synchronously from the default destination, but only wait up to a specified time for delivery. |
| public Message | receiveSelected(final Destination
the destination to receive a message from destination, final String the JMS message selector expression (or messageSelector)null if none).
See the JMS specification for a detailed definition of selector expressions.Implements org. Receive a message synchronously from the specified destination, but only wait up to a specified time for delivery. |
| public Message | receiveSelected(final String
the name of the destination to send this message to
(to be resolved to an actual destination by a DestinationResolver) destinationName, final String the JMS message selector expression (or messageSelector)null if none).
See the JMS specification for a detailed definition of selector expressions.Implements org. Receive a message synchronously from the specified destination, but only wait up to a specified time for delivery. |
| public Object | receiveSelectedAndConvert(String
the JMS message selector expression (or messageSelector)null if none).
See the JMS specification for a detailed definition of selector expressions.Implements org. Receive a message synchronously from the default destination, but only wait up to a specified time for delivery. |
| public Object | receiveSelectedAndConvert(Destination
the destination to receive a message from destination, String the JMS message selector expression (or messageSelector)null if none).
See the JMS specification for a detailed definition of selector expressions.Implements org. Receive a message synchronously from the specified destination, but only wait up to a specified time for delivery. |
| public Object | receiveSelectedAndConvert(String
the name of the destination to send this message to
(to be resolved to an actual destination by a DestinationResolver) destinationName, String the JMS message selector expression (or messageSelector)null if none).
See the JMS specification for a detailed definition of selector expressions.Implements org. Receive a message synchronously from the specified destination, but only wait up to a specified time for delivery. |
| public void | send(MessageCreator
callback to create a message messageCreator)Implements org. Send a message to the default destination. |
| public void | send(final Destination
the destination to send this message to destination, final MessageCreator callback to create a message messageCreator)Implements org. Send a message to the specified destination. |
| public void | send(final String
the name of the destination to send this message to
(to be resolved to an actual destination by a DestinationResolver) destinationName, final MessageCreator callback to create a message messageCreator)Implements org. Send a message to the specified destination. |
| public Message | sendAndReceive(MessageCreator
callback to create a request message messageCreator)Implements org. Send a request message and receive the reply from a default destination. |
| public Message | sendAndReceive(final Destination
the destination to send this message to destination, final MessageCreator callback to create a message messageCreator)Implements org. Send a message and receive the reply from the specified destination. |
| public Message | sendAndReceive(final String
the name of the destination to send this message to
(to be resolved to an actual destination by a DestinationResolver) destinationName, final MessageCreator callback to create a message messageCreator)Implements org. Send a message and receive the reply from the specified destination. |
| public void | setDefaultDestination(Destination destination)
Set the destination to be used on send/receive operations that do not have a destination parameter. |
| public void | setDefaultDestinationName(String destinationName)
Set the destination name to be used on send/receive operations that do not have a destination parameter. |
| public void | |
| public void | setDeliveryMode(int
the delivery mode to use deliveryMode)Set the delivery mode to use when sending a message. |
| public void | setDeliveryPersistent(boolean deliveryPersistent)
Set whether message delivery should be persistent or non-persistent, specified as boolean value ("true" or "false"). |
| public void | setExplicitQosEnabled(boolean explicitQosEnabled)
Set if the QOS values (deliveryMode, priority, timeToLive) should be used for sending a message. |
| public void | |
| public void | |
| public void | setMessageTimestampEnabled(boolean messageTimestampEnabled)
Set whether message timestamps are enabled. |
| public void | setObservationRegistry(ObservationRegistry
the observation registry to use. observationRegistry)Configure the |
| public void | |
| public void | setPubSubNoLocal(boolean pubSubNoLocal)
Set whether to inhibit the delivery of messages published by its own connection. |
| public void | setQosSettings(QosSettings
the deliveryMode, priority, and timeToLive settings to use settings)Set the |
| public void | |
| public void | setTimeToLive(long
the message's lifetime (in milliseconds) timeToLive)Set the time-to-live of the message when sending. |