Helper class that simplifies synchronous JMS access code.
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 Java 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
DynamicDestinationResolver
and a SimpleMessageConverter
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
SingleConnectionFactory 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 Java 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.
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.
Note: The ConnectionFactory has to be set before using the instance.
This constructor can be used to prepare a JmsTemplate via a BeanFactory,
typically setting the ConnectionFactory via setConnectionFactory.
Return the destination to be used on send/receive operations that do not
have a destination parameter.
setDefaultDestinationName
public void setDefaultDestinationName(@Nullable
java.lang.String destinationName)
Set the destination name to be used on send/receive operations that
do not have a destination parameter. The specified name will be
dynamically resolved via the DestinationResolver.
Alternatively, specify a JMS Destination object as "defaultDestination".
Set the message converter for this template. Used to resolve
Object parameters to convertAndSend methods and Object results
from receiveAndConvert methods.
The default converter is a SimpleMessageConverter, which is able
to handle BytesMessages, TextMessages and ObjectMessages.
Specify JmsDestinationAccessor.RECEIVE_TIMEOUT_NO_WAIT (or any other negative value)
to indicate that a receive operation should check if a message is
immediately available without blocking.
If "true", then the values of deliveryMode, priority, and timeToLive
will be used when sending a message. Otherwise, the default values,
that may be set administratively, will be used.
Returns:
true if overriding default values of QOS parameters
(deliveryMode, priority, and timeToLive)
public void setDeliveryPersistent(boolean deliveryPersistent)
Set whether message delivery should be persistent or non-persistent,
specified as boolean value ("true" or "false"). This will set the delivery
mode accordingly, to either "PERSISTENT" (2) or "NON_PERSISTENT" (1).
Default is "true" a.k.a. delivery mode "PERSISTENT".
Execute the action specified by the given action object within a
JMS Session. Generalized version of execute(SessionCallback),
allowing the JMS Connection to be started on the fly.
Use execute(SessionCallback) for the general case.
Starting the JMS Connection is just necessary for receiving messages,
which is preferably achieved through the receive methods.
Send messages to the default JMS destination (or one specified
for each send operation). The callback gives access to the JMS Session
and MessageProducer in order to perform complex send operations.
Send the given object to the default destination, converting the object
to a JMS message with a configured MessageConverter. The MessagePostProcessor
callback allows for modification of the message after conversion.
This will only work with a default destination specified!
Send the given object to the specified destination, converting the object
to a JMS message with a configured MessageConverter. The MessagePostProcessor
callback allows for modification of the message after conversion.
Send the given object to the specified destination, converting the object
to a JMS message with a configured MessageConverter. The MessagePostProcessor
callback allows for modification of the message after conversion.
Receive a message synchronously from the default destination, but only
wait up to a specified time for delivery. Convert the message into an
object with a configured MessageConverter.
This method should be used carefully, since it will block the thread
until the message becomes available or until the timeout value is exceeded.
This will only work with a default destination specified!
Receive a message synchronously from the specified destination, but only
wait up to a specified time for delivery. Convert the message into an
object with a configured MessageConverter.
This method should be used carefully, since it will block the thread
until the message becomes available or until the timeout value is exceeded.
Receive a message synchronously from the specified destination, but only
wait up to a specified time for delivery. Convert the message into an
object with a configured MessageConverter.
This method should be used carefully, since it will block the thread
until the message becomes available or until the timeout value is exceeded.
Receive a message synchronously from the default destination, but only
wait up to a specified time for delivery. Convert the message into an
object with a configured MessageConverter.
This method should be used carefully, since it will block the thread
until the message becomes available or until the timeout value is exceeded.
This will only work with a default destination specified!
Receive a message synchronously from the specified destination, but only
wait up to a specified time for delivery. Convert the message into an
object with a configured MessageConverter.
This method should be used carefully, since it will block the thread
until the message becomes available or until the timeout value is exceeded.
Receive a message synchronously from the specified destination, but only
wait up to a specified time for delivery. Convert the message into an
object with a configured MessageConverter.
This method should be used carefully, since it will block the thread
until the message becomes available or until the timeout value is exceeded.
Send a request message and receive the reply from a default destination. The
MessageCreator callback creates the message given a Session. A temporary
queue is created as part of this operation and is set in the JMSReplyTO
header of the message.
This will only work with a default destination specified!
Send a message and receive the reply from the specified destination. The
MessageCreator callback creates the message given a Session. A temporary
queue is created as part of this operation and is set in the JMSReplyTO
header of the message.
Send a message and receive the reply from the specified destination. The
MessageCreator callback creates the message given a Session. A temporary
queue is created as part of this operation and is set in the JMSReplyTO
header of the message.
Browse messages in the default JMS queue. The callback gives access to the JMS
Session and QueueBrowser in order to browse the queue and react to the contents.
Browse selected messages in a JMS queue. The callback gives access to the JMS
Session and QueueBrowser in order to browse the queue and react to the contents.
Browse selected messages in a JMS queue. The callback gives access to the JMS
Session and QueueBrowser in order to browse the queue and react to the contents.
Browse selected messages in a JMS queue. The callback gives access to the JMS
Session and QueueBrowser in order to browse the queue and react to the contents.
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.
Note: The Session's own transacted flag will already have been checked
before. This method is about finding out whether the Session's transaction
is local or externally coordinated.