java.lang.Object | |||
↳ | org.springframework.jms.support.JmsAccessor | ||
↳ | org.springframework.jms.support.destination.JmsDestinationAccessor | ||
↳ | org.springframework.jms.core.JmsTemplate |
Known Direct Subclasses |
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, in contrast to when working
with JmsTemplate102
. Point-to-Point (Queues) is the default domain.
Default settings for JMS Sessions are "not transacted" and "auto-acknowledge". As defined by the J2EE 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 J2EE 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(ConnectionFactory)
setPubSubDomain(boolean)
setDestinationResolver(DestinationResolver)
setMessageConverter(MessageConverter)
Constants | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
long | RECEIVE_TIMEOUT_INDEFINITE_WAIT | Timeout value indicating a blocking receive without timeout. | |||||||||
long | RECEIVE_TIMEOUT_NO_WAIT | Timeout value indicating that a receive operation should check if a message is immediately available without blocking. |
[Expand]
Inherited Fields | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
From class
org.springframework.jms.support.JmsAccessor
|
Public Constructors | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
Create a new JmsTemplate for bean-style usage.
| |||||||||||
Create a new JmsTemplate, given a ConnectionFactory.
|
Public Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
Browse messages in the default JMS queue.
| |||||||||||
Browse messages in a JMS queue.
| |||||||||||
Browse selected messages in a JMS queue.
| |||||||||||
Browse selected messages in a JMS queue.
| |||||||||||
Send the given object to the default destination, converting the object
to a JMS message with a configured MessageConverter.
| |||||||||||
Send the given object to the specified destination, converting the object
to a JMS message with a configured MessageConverter.
| |||||||||||
Send the given object to the specified destination, converting the object
to a JMS message with a configured MessageConverter.
| |||||||||||
Send the given object to the default destination, converting the object
to a JMS message with a configured MessageConverter.
| |||||||||||
Send messages to the default JMS destination (or one specified
for each send operation).
| |||||||||||
Send messages to a JMS destination.
| |||||||||||
Execute the action specified by the given action object within a JMS Session.
| |||||||||||
Execute the action specified by the given action object within a
JMS Session.
| |||||||||||
Return the destination to be used on send/receive operations that do not
have a destination parameter.
| |||||||||||
Return the destination name to be used on send/receive operations that
do not have a destination parameter.
| |||||||||||
Return the delivery mode to use when sending a message.
| |||||||||||
Return the message converter for this template.
| |||||||||||
Return the priority of a message when sending.
| |||||||||||
Return the timeout to use for receive calls (in milliseconds).
| |||||||||||
Return the time-to-live of the message when sending.
| |||||||||||
If "true", then the values of deliveryMode, priority, and timeToLive
will be used when sending a message.
| |||||||||||
Return whether message IDs are enabled.
| |||||||||||
Return whether message timestamps are enabled.
| |||||||||||
Return whether to inhibit the delivery of messages published by its own connection.
| |||||||||||
Receive a message synchronously from the default destination, but only
wait up to a specified time for delivery.
| |||||||||||
Receive a message synchronously from the specified destination, but only
wait up to a specified time for delivery.
| |||||||||||
Receive a message synchronously from the specified destination, but only
wait up to a specified time for delivery.
| |||||||||||
Receive a message synchronously from the default destination, but only
wait up to a specified time for delivery.
| |||||||||||
Receive a message synchronously from the specified destination, but only
wait up to a specified time for delivery.
| |||||||||||
Receive a message synchronously from the specified destination, but only
wait up to a specified time for delivery.
| |||||||||||
Receive a message synchronously from the default destination, but only
wait up to a specified time for delivery.
| |||||||||||
Receive a message synchronously from the specified destination, but only
wait up to a specified time for delivery.
| |||||||||||
Receive a message synchronously from the default destination, but only
wait up to a specified time for delivery.
| |||||||||||
Receive a message synchronously from the specified destination, but only
wait up to a specified time for delivery.
| |||||||||||
Send a message to the specified destination.
| |||||||||||
Send a message to the default destination.
| |||||||||||
Set the destination to be used on send/receive operations that do not
have a destination parameter.
| |||||||||||
Set the destination name to be used on send/receive operations that
do not have a destination parameter.
| |||||||||||
Set the delivery mode to use when sending a message.
| |||||||||||
Set whether message delivery should be persistent or non-persistent,
specified as boolean value ("true" or "false").
| |||||||||||
Set if the QOS values (deliveryMode, priority, timeToLive)
should be used for sending a message.
| |||||||||||
Set the message converter for this template.
| |||||||||||
Set whether message IDs are enabled.
| |||||||||||
Set whether message timestamps are enabled.
| |||||||||||
Set the priority of a message when sending.
| |||||||||||
Set whether to inhibit the delivery of messages published by its own connection.
| |||||||||||
Set the timeout to use for receive calls (in milliseconds).
| |||||||||||
Set the time-to-live of the message when sending.
|
Protected Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
Create a JMS MessageProducer for the given Session and Destination,
configuring it to disable message ids and/or timestamps (if necessary).
| |||||||||||
Create a JMS MessageConsumer for the given Session and Destination.
| |||||||||||
Create a JMS MessageProducer for the given Session and Destination,
configuring it to disable message ids and/or timestamps (if necessary).
| |||||||||||
Extract the content from the given JMS message.
| |||||||||||
Create a raw JMS MessageProducer for the given Session and Destination.
| |||||||||||
Receive a JMS message.
| |||||||||||
Actually receive a JMS message.
| |||||||||||
Actually send the given JMS message.
| |||||||||||
Send the given JMS message.
| |||||||||||
Fetch an appropriate Connection from the given JmsResourceHolder.
| |||||||||||
Fetch an appropriate Session from the given JmsResourceHolder.
| |||||||||||
Initialize the default implementations for the template's strategies:
DynamicDestinationResolver and SimpleMessageConverter.
| |||||||||||
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.
|
[Expand]
Inherited Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
From class
org.springframework.jms.support.destination.JmsDestinationAccessor
| |||||||||||
From class
org.springframework.jms.support.JmsAccessor
| |||||||||||
From class
java.lang.Object
| |||||||||||
From interface
org.springframework.beans.factory.InitializingBean
| |||||||||||
From interface
org.springframework.jms.core.JmsOperations
|
Timeout value indicating a blocking receive without timeout.
Timeout value indicating that a receive operation should check if a message is immediately available without blocking.
Create a new JmsTemplate for bean-style usage.
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.
Create a new JmsTemplate, given a ConnectionFactory.
connectionFactory | the ConnectionFactory to obtain Connections from |
---|
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.
action | callback object that exposes the session/browser pair |
---|
JmsException |
---|
Browse 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.
queue | the queue to browse |
---|---|
action | callback object that exposes the session/browser pair |
JmsException |
---|
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.
queue | the queue to browse |
---|---|
messageSelector | the JMS message selector expression (or null if none).
See the JMS specification for a detailed definition of selector expressions. |
action | callback object that exposes the session/browser pair |
JmsException |
---|
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.
messageSelector | the JMS message selector expression (or null if none).
See the JMS specification for a detailed definition of selector expressions. |
---|---|
action | callback object that exposes the session/browser pair |
JmsException |
---|
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!
message | the object to convert to a message |
---|---|
postProcessor | the callback to modify the message |
JmsException |
---|
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.
destination | the destination to send this message to |
---|---|
message | the object to convert to a message |
postProcessor | the callback to modify the message |
JmsException |
---|
Send the given object to the specified destination, converting the object to a JMS message with a configured MessageConverter.
destination | the destination to send this message to |
---|---|
message | the object to convert to a message |
JmsException |
---|
Send the given object to the default destination, converting the object to a JMS message with a configured MessageConverter.
This will only work with a default destination specified!
message | the object to convert to a message |
---|
JmsException |
---|
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.
action | callback object that exposes the session/producer pair |
---|
JmsException |
---|
Send messages to a JMS destination. The callback gives access to the JMS Session and MessageProducer in order to perform complex send operations.
destination | the destination to send messages to |
---|---|
action | callback object that exposes the session/producer pair |
JmsException |
---|
Execute the action specified by the given action object within a JMS Session.
When used with a 1.0.2 provider, you may need to downcast to the appropriate domain implementation, either QueueSession or TopicSession in the action objects doInJms callback method.
action | callback object that exposes the session |
---|
JmsException |
---|
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.
action | callback object that exposes the Session |
---|---|
startConnection | whether to start the Connection |
JmsException | if there is any problem |
---|
Return the destination to be used on send/receive operations that do not have a destination parameter.
Return the destination name to be used on send/receive operations that do not have a destination parameter.
Return the delivery mode to use when sending a message.
Return the priority of a message when sending.
Return the timeout to use for receive calls (in milliseconds).
Return the time-to-live of the message when sending.
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.
Return whether message IDs are enabled.
Return whether message timestamps are enabled.
Return whether to inhibit the delivery of messages published by its own connection.
Receive a message synchronously from the default destination, but only wait up to a specified time for delivery.
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!
null
if the timeout expiresJmsException |
---|
Receive a message synchronously from the specified destination, but only wait up to a specified time for delivery.
This method should be used carefully, since it will block the thread until the message becomes available or until the timeout value is exceeded.
destinationName | the name of the destination to send this message to (to be resolved to an actual destination by a DestinationResolver) |
---|
null
if the timeout expiresJmsException |
---|
Receive a message synchronously from the specified destination, but only wait up to a specified time for delivery.
This method should be used carefully, since it will block the thread until the message becomes available or until the timeout value is exceeded.
destination | the destination to receive a message from |
---|
null
if the timeout expiresJmsException |
---|
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!
null
if the timeout expires.JmsException |
---|
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.
destination | the destination to receive a message from |
---|
null
if the timeout expires.JmsException |
---|
Receive a message synchronously from the specified destination, but only wait up to a specified time for delivery.
This method should be used carefully, since it will block the thread until the message becomes available or until the timeout value is exceeded.
destinationName | the name of the destination to send this message to (to be resolved to an actual destination by a DestinationResolver) |
---|---|
messageSelector | the JMS message selector expression (or null if none).
See the JMS specification for a detailed definition of selector expressions. |
null
if the timeout expiresJmsException |
---|
Receive a message synchronously from the default destination, but only wait up to a specified time for delivery.
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!
messageSelector | the JMS message selector expression (or null if none).
See the JMS specification for a detailed definition of selector expressions. |
---|
null
if the timeout expiresJmsException |
---|
Receive a message synchronously from the specified destination, but only wait up to a specified time for delivery.
This method should be used carefully, since it will block the thread until the message becomes available or until the timeout value is exceeded.
destination | the destination to receive a message from |
---|---|
messageSelector | the JMS message selector expression (or null if none).
See the JMS specification for a detailed definition of selector expressions. |
null
if the timeout expiresJmsException |
---|
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!
messageSelector | the JMS message selector expression (or null if none).
See the JMS specification for a detailed definition of selector expressions. |
---|
null
if the timeout expires.JmsException |
---|
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.
destination | the destination to receive a message from |
---|---|
messageSelector | the JMS message selector expression (or null if none).
See the JMS specification for a detailed definition of selector expressions. |
null
if the timeout expires.JmsException |
---|
Send a message to the specified destination. The MessageCreator callback creates the message given a Session.
destination | the destination to send this message to |
---|---|
messageCreator | callback to create a message |
JmsException |
---|
Send a message to the default destination.
This will only work with a default destination specified!
messageCreator | callback to create a message |
---|
JmsException |
---|
Set the destination to be used on send/receive operations that do not have a destination parameter.
Alternatively, specify a "defaultDestinationName", to be dynamically resolved via the DestinationResolver.
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".
send(MessageCreator)
convertAndSend(Object)
convertAndSend(Object, MessagePostProcessor)
setDestinationResolver(DestinationResolver)
Set the delivery mode to use when sending a message. Default is the Message default: "PERSISTENT".
Since a default value may be defined administratively, this is only used when "isExplicitQosEnabled" equals "true".
deliveryMode | the delivery mode to use |
---|
isExplicitQosEnabled()
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" (1) or "NON_PERSISTENT" (2).
Default it "true" aka delivery mode "PERSISTENT".
setDeliveryMode(int)
Set if the QOS values (deliveryMode, priority, timeToLive) should be used for sending a message.
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.
Set whether message IDs are enabled. Default is "true".
This is only a hint to the JMS producer. See the JMS javadocs for details.
Set whether message timestamps are enabled. Default is "true".
This is only a hint to the JMS producer. See the JMS javadocs for details.
Set the priority of a message when sending.
Since a default value may be defined administratively, this is only used when "isExplicitQosEnabled" equals "true".
isExplicitQosEnabled()
Set whether to inhibit the delivery of messages published by its own connection. Default is "false".
Set the timeout to use for receive calls (in milliseconds).
The default is RECEIVE_TIMEOUT_INDEFINITE_WAIT
, which indicates
a blocking receive without timeout.
Specify RECEIVE_TIMEOUT_NO_WAIT
to inidicate that a receive operation
should check if a message is immediately available without blocking.
Set the time-to-live of the message when sending.
Since a default value may be defined administratively, this is only used when "isExplicitQosEnabled" equals "true".
timeToLive | the message's lifetime (in milliseconds) |
---|
isExplicitQosEnabled()
Create a JMS MessageProducer for the given Session and Destination, configuring it to disable message ids and/or timestamps (if necessary).
Delegates to doCreateProducer(Session, Destination)
for creation of the raw
JMS MessageProducer, which needs to be specific to JMS 1.1 or 1.0.2.
session | the JMS Session to create a QueueBrowser for |
---|---|
queue | the JMS Queue to create a QueueBrowser for |
messageSelector | the message selector for this consumer (can be null ) |
if thrown by JMS API methods | |
JMSException |
Create a JMS MessageConsumer for the given Session and Destination.
This implementation uses JMS 1.1 API.
session | the JMS Session to create a MessageConsumer for |
---|---|
destination | the JMS Destination to create a MessageConsumer for |
messageSelector | the message selector for this consumer (can be null ) |
if thrown by JMS API methods | |
JMSException |
Create a JMS MessageProducer for the given Session and Destination, configuring it to disable message ids and/or timestamps (if necessary).
Delegates to doCreateProducer(Session, Destination)
for creation of the raw
JMS MessageProducer, which needs to be specific to JMS 1.1 or 1.0.2.
session | the JMS Session to create a MessageProducer for |
---|---|
destination | the JMS Destination to create a MessageProducer for |
if thrown by JMS API methods | |
JMSException |
Extract the content from the given JMS message.
message | the JMS Message to convert (can be null ) |
---|
null
if none
Create a raw JMS MessageProducer for the given Session and Destination.
This implementation uses JMS 1.1 API.
session | the JMS Session to create a MessageProducer for |
---|---|
destination | the JMS Destination to create a MessageProducer for |
if thrown by JMS API methods | |
JMSException |
Receive a JMS message.
session | the JMS Session to operate on |
---|---|
destination | the JMS Destination to receive from |
messageSelector | the message selector for this consumer (can be null ) |
null
if noneif thrown by JMS API methods | |
JMSException |
Actually receive a JMS message.
session | the JMS Session to operate on |
---|---|
consumer | the JMS MessageConsumer to receive with |
null
if noneif thrown by JMS API methods | |
JMSException |
Actually send the given JMS message.
producer | the JMS MessageProducer to send with |
---|---|
message | the JMS Message to send |
if thrown by JMS API methods | |
JMSException |
Send the given JMS message.
session | the JMS Session to operate on |
---|---|
destination | the JMS Destination to send to |
messageCreator | callback to create a JMS Message |
if thrown by JMS API methods | |
JMSException |
Fetch an appropriate Connection from the given JmsResourceHolder.
This implementation accepts any JMS 1.1 Connection.
holder | the JmsResourceHolder |
---|
null
if none found
Fetch an appropriate Session from the given JmsResourceHolder.
This implementation accepts any JMS 1.1 Session.
holder | the JmsResourceHolder |
---|
null
if none found
Initialize the default implementations for the template's strategies: DynamicDestinationResolver and SimpleMessageConverter.
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.
session | the Session to check |
---|