public class

JmsTemplate

extends JmsDestinationAccessor
implements JmsOperations
java.lang.Object
   ↳ org.springframework.jms.support.JmsAccessor
     ↳ org.springframework.jms.support.destination.JmsDestinationAccessor
       ↳ org.springframework.jms.core.JmsTemplate
Known Direct Subclasses

Class Overview

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.

Summary

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
JmsTemplate()
Create a new JmsTemplate for bean-style usage.
JmsTemplate(ConnectionFactory connectionFactory)
Create a new JmsTemplate, given a ConnectionFactory.
Public Methods
<T> T browse(BrowserCallback<T> action)
Browse messages in the default JMS queue.
<T> T browse(Queue queue, BrowserCallback<T> action)
Browse messages in a JMS queue.
<T> T browseSelected(Queue queue, String messageSelector, BrowserCallback<T> action)
Browse selected messages in a JMS queue.
<T> T browseSelected(String messageSelector, BrowserCallback<T> action)
Browse selected messages in a JMS queue.
void convertAndSend(Object message, MessagePostProcessor postProcessor)
Send the given object to the default destination, converting the object to a JMS message with a configured MessageConverter.
void convertAndSend(Destination destination, Object message, MessagePostProcessor postProcessor)
Send the given object to the specified destination, converting the object to a JMS message with a configured MessageConverter.
void convertAndSend(Destination destination, Object message)
Send the given object to the specified destination, converting the object to a JMS message with a configured MessageConverter.
void convertAndSend(Object message)
Send the given object to the default destination, converting the object to a JMS message with a configured MessageConverter.
<T> T execute(ProducerCallback<T> action)
Send messages to the default JMS destination (or one specified for each send operation).
<T> T execute(Destination destination, ProducerCallback<T> action)
Send messages to a JMS destination.
<T> T execute(SessionCallback<T> action)
Execute the action specified by the given action object within a JMS Session.
<T> T execute(SessionCallback<T> action, boolean startConnection)
Execute the action specified by the given action object within a JMS Session.
Destination getDefaultDestination()
Return the destination to be used on send/receive operations that do not have a destination parameter.
String getDefaultDestinationName()
Return the destination name to be used on send/receive operations that do not have a destination parameter.
int getDeliveryMode()
Return the delivery mode to use when sending a message.
MessageConverter getMessageConverter()
Return the message converter for this template.
int getPriority()
Return the priority of a message when sending.
long getReceiveTimeout()
Return the timeout to use for receive calls (in milliseconds).
long getTimeToLive()
Return the time-to-live of the message when sending.
boolean isExplicitQosEnabled()
If "true", then the values of deliveryMode, priority, and timeToLive will be used when sending a message.
boolean isMessageIdEnabled()
Return whether message IDs are enabled.
boolean isMessageTimestampEnabled()
Return whether message timestamps are enabled.
boolean isPubSubNoLocal()
Return whether to inhibit the delivery of messages published by its own connection.
Message receive()
Receive a message synchronously from the default destination, but only wait up to a specified time for delivery.
Message receive(String destinationName)
Receive a message synchronously from the specified destination, but only wait up to a specified time for delivery.
Message receive(Destination destination)
Receive a message synchronously from the specified destination, but only wait up to a specified time for delivery.
Object receiveAndConvert()
Receive a message synchronously from the default destination, but only wait up to a specified time for delivery.
Object receiveAndConvert(Destination destination)
Receive a message synchronously from the specified destination, but only wait up to a specified time for delivery.
Message receiveSelected(String destinationName, String messageSelector)
Receive a message synchronously from the specified destination, but only wait up to a specified time for delivery.
Message receiveSelected(String messageSelector)
Receive a message synchronously from the default destination, but only wait up to a specified time for delivery.
Message receiveSelected(Destination destination, String messageSelector)
Receive a message synchronously from the specified destination, but only wait up to a specified time for delivery.
Object receiveSelectedAndConvert(String messageSelector)
Receive a message synchronously from the default destination, but only wait up to a specified time for delivery.
Object receiveSelectedAndConvert(Destination destination, String messageSelector)
Receive a message synchronously from the specified destination, but only wait up to a specified time for delivery.
void send(Destination destination, MessageCreator messageCreator)
Send a message to the specified destination.
void send(MessageCreator messageCreator)
Send a message to the default destination.
void setDefaultDestination(Destination destination)
Set the destination to be used on send/receive operations that do not have a destination parameter.
void setDefaultDestinationName(String destinationName)
Set the destination name to be used on send/receive operations that do not have a destination parameter.
void setDeliveryMode(int deliveryMode)
Set the delivery mode to use when sending a message.
void setDeliveryPersistent(boolean deliveryPersistent)
Set whether message delivery should be persistent or non-persistent, specified as boolean value ("true" or "false").
void setExplicitQosEnabled(boolean explicitQosEnabled)
Set if the QOS values (deliveryMode, priority, timeToLive) should be used for sending a message.
void setMessageConverter(MessageConverter messageConverter)
Set the message converter for this template.
void setMessageIdEnabled(boolean messageIdEnabled)
Set whether message IDs are enabled.
void setMessageTimestampEnabled(boolean messageTimestampEnabled)
Set whether message timestamps are enabled.
void setPriority(int priority)
Set the priority of a message when sending.
void setPubSubNoLocal(boolean pubSubNoLocal)
Set whether to inhibit the delivery of messages published by its own connection.
void setReceiveTimeout(long receiveTimeout)
Set the timeout to use for receive calls (in milliseconds).
void setTimeToLive(long timeToLive)
Set the time-to-live of the message when sending.
Protected Methods
QueueBrowser createBrowser(Session session, Queue queue, String messageSelector)
Create a JMS MessageProducer for the given Session and Destination, configuring it to disable message ids and/or timestamps (if necessary).
MessageConsumer createConsumer(Session session, Destination destination, String messageSelector)
Create a JMS MessageConsumer for the given Session and Destination.
MessageProducer createProducer(Session session, Destination destination)
Create a JMS MessageProducer for the given Session and Destination, configuring it to disable message ids and/or timestamps (if necessary).
Object doConvertFromMessage(Message message)
Extract the content from the given JMS message.
MessageProducer doCreateProducer(Session session, Destination destination)
Create a raw JMS MessageProducer for the given Session and Destination.
Message doReceive(Session session, Destination destination, String messageSelector)
Receive a JMS message.
Message doReceive(Session session, MessageConsumer consumer)
Actually receive a JMS message.
void doSend(MessageProducer producer, Message message)
Actually send the given JMS message.
void doSend(Session session, Destination destination, MessageCreator messageCreator)
Send the given JMS message.
Connection getConnection(JmsResourceHolder holder)
Fetch an appropriate Connection from the given JmsResourceHolder.
Session getSession(JmsResourceHolder holder)
Fetch an appropriate Session from the given JmsResourceHolder.
void initDefaultStrategies()
Initialize the default implementations for the template's strategies: DynamicDestinationResolver and SimpleMessageConverter.
boolean isSessionLocallyTransacted(Session 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.
[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

Constants

public static final long RECEIVE_TIMEOUT_INDEFINITE_WAIT

Timeout value indicating a blocking receive without timeout.

Constant Value: 0 (0x0000000000000000)

public static final long RECEIVE_TIMEOUT_NO_WAIT

Timeout value indicating that a receive operation should check if a message is immediately available without blocking.

Constant Value: -1 (0xffffffffffffffff)

Public Constructors

public JmsTemplate ()

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.

public JmsTemplate (ConnectionFactory connectionFactory)

Create a new JmsTemplate, given a ConnectionFactory.

Parameters
connectionFactory the ConnectionFactory to obtain Connections from

Public Methods

public T browse (BrowserCallback<T> action)

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.

Parameters
action callback object that exposes the session/browser pair
Returns
  • the result object from working with the session
Throws
JmsException

public T browse (Queue queue, BrowserCallback<T> action)

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.

Parameters
queue the queue to browse
action callback object that exposes the session/browser pair
Returns
  • the result object from working with the session
Throws
JmsException

public T browseSelected (Queue queue, String messageSelector, BrowserCallback<T> action)

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.

Parameters
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
Returns
  • the result object from working with the session
Throws
JmsException

public T browseSelected (String messageSelector, BrowserCallback<T> action)

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.

Parameters
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
Returns
  • the result object from working with the session
Throws
JmsException

public void convertAndSend (Object message, MessagePostProcessor postProcessor)

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!

Parameters
message the object to convert to a message
postProcessor the callback to modify the message
Throws
JmsException

public void convertAndSend (Destination destination, Object message, MessagePostProcessor postProcessor)

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.

Parameters
destination the destination to send this message to
message the object to convert to a message
postProcessor the callback to modify the message
Throws
JmsException

public void convertAndSend (Destination destination, Object message)

Send the given object to the specified destination, converting the object to a JMS message with a configured MessageConverter.

Parameters
destination the destination to send this message to
message the object to convert to a message
Throws
JmsException

public void convertAndSend (Object message)

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!

Parameters
message the object to convert to a message
Throws
JmsException

public T execute (ProducerCallback<T> action)

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.

Parameters
action callback object that exposes the session/producer pair
Returns
  • the result object from working with the session
Throws
JmsException

public T execute (Destination destination, ProducerCallback<T> action)

Send messages to a JMS destination. The callback gives access to the JMS Session and MessageProducer in order to perform complex send operations.

Parameters
destination the destination to send messages to
action callback object that exposes the session/producer pair
Returns
  • the result object from working with the session
Throws
JmsException

public T execute (SessionCallback<T> action)

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.

Parameters
action callback object that exposes the session
Returns
  • the result object from working with the session
Throws
JmsException

public T execute (SessionCallback<T> action, boolean startConnection)

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.

Parameters
action callback object that exposes the Session
startConnection whether to start the Connection
Returns
  • the result object from working with the Session
Throws
JmsException if there is any problem

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.

public int getDeliveryMode ()

Return the delivery mode to use when sending a message.

public MessageConverter getMessageConverter ()

Return the message converter for this template.

public int getPriority ()

Return the priority of a message when sending.

public long getReceiveTimeout ()

Return the timeout to use for receive calls (in milliseconds).

public long getTimeToLive ()

Return the time-to-live of the message when sending.

public boolean isExplicitQosEnabled ()

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 boolean isMessageIdEnabled ()

Return whether message IDs are enabled.

public boolean isMessageTimestampEnabled ()

Return whether message timestamps are enabled.

public boolean isPubSubNoLocal ()

Return whether to inhibit the delivery of messages published by its own connection.

public Message receive ()

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!

Returns
  • the message received by the consumer, or null if the timeout expires
Throws
JmsException

public Message receive (String destinationName)

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.

Parameters
destinationName the name of the destination to send this message to (to be resolved to an actual destination by a DestinationResolver)
Returns
  • the message received by the consumer, or null if the timeout expires
Throws
JmsException

public Message receive (Destination destination)

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.

Parameters
destination the destination to receive a message from
Returns
  • the message received by the consumer, or null if the timeout expires
Throws
JmsException

public Object receiveAndConvert ()

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!

Returns
  • the message produced for the consumer or null if the timeout expires.
Throws
JmsException

public Object receiveAndConvert (Destination destination)

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.

Parameters
destination the destination to receive a message from
Returns
  • the message produced for the consumer or null if the timeout expires.
Throws
JmsException

public Message receiveSelected (String destinationName, String messageSelector)

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.

Parameters
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.
Returns
  • the message received by the consumer, or null if the timeout expires
Throws
JmsException

public Message receiveSelected (String messageSelector)

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!

Parameters
messageSelector the JMS message selector expression (or null if none). See the JMS specification for a detailed definition of selector expressions.
Returns
  • the message received by the consumer, or null if the timeout expires
Throws
JmsException

public Message receiveSelected (Destination destination, String messageSelector)

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.

Parameters
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.
Returns
  • the message received by the consumer, or null if the timeout expires
Throws
JmsException

public Object receiveSelectedAndConvert (String messageSelector)

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!

Parameters
messageSelector the JMS message selector expression (or null if none). See the JMS specification for a detailed definition of selector expressions.
Returns
  • the message produced for the consumer or null if the timeout expires.
Throws
JmsException

public Object receiveSelectedAndConvert (Destination destination, String messageSelector)

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.

Parameters
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.
Returns
  • the message produced for the consumer or null if the timeout expires.
Throws
JmsException

public void send (Destination destination, MessageCreator messageCreator)

Send a message to the specified destination. The MessageCreator callback creates the message given a Session.

Parameters
destination the destination to send this message to
messageCreator callback to create a message
Throws
JmsException

public void send (MessageCreator messageCreator)

Send a message to the default destination.

This will only work with a default destination specified!

Parameters
messageCreator callback to create a message
Throws
JmsException

public void setDefaultDestination (Destination destination)

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.

public void setDefaultDestinationName (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".

public void setDeliveryMode (int deliveryMode)

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".

Parameters
deliveryMode the delivery mode to use
See Also
  • isExplicitQosEnabled()
  • javax.jms.DeliveryMode#PERSISTENT
  • javax.jms.DeliveryMode#NON_PERSISTENT
  • javax.jms.Message#DEFAULT_DELIVERY_MODE
  • javax.jms.MessageProducer#send(javax.jms.Message, int, int, long)

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" (1) or "NON_PERSISTENT" (2).

Default it "true" aka delivery mode "PERSISTENT".

See Also

public void setExplicitQosEnabled (boolean explicitQosEnabled)

Set if the QOS values (deliveryMode, priority, timeToLive) should be used for sending a message.

public void setMessageConverter (MessageConverter messageConverter)

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.

public void setMessageIdEnabled (boolean messageIdEnabled)

Set whether message IDs are enabled. Default is "true".

This is only a hint to the JMS producer. See the JMS javadocs for details.

See Also
  • javax.jms.MessageProducer#setDisableMessageID

public void setMessageTimestampEnabled (boolean messageTimestampEnabled)

Set whether message timestamps are enabled. Default is "true".

This is only a hint to the JMS producer. See the JMS javadocs for details.

See Also
  • javax.jms.MessageProducer#setDisableMessageTimestamp

public void setPriority (int priority)

Set the priority of a message when sending.

Since a default value may be defined administratively, this is only used when "isExplicitQosEnabled" equals "true".

See Also
  • isExplicitQosEnabled()
  • javax.jms.Message#DEFAULT_PRIORITY
  • javax.jms.MessageProducer#send(javax.jms.Message, int, int, long)

public void setPubSubNoLocal (boolean pubSubNoLocal)

Set whether to inhibit the delivery of messages published by its own connection. Default is "false".

See Also
  • javax.jms.TopicSession#createSubscriber(javax.jms.Topic, String, boolean)

public void setReceiveTimeout (long receiveTimeout)

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.

See Also
  • javax.jms.MessageConsumer#receive(long)
  • javax.jms.MessageConsumer#receive()
  • javax.jms.MessageConsumer#receiveNoWait()

public void setTimeToLive (long timeToLive)

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".

Parameters
timeToLive the message's lifetime (in milliseconds)
See Also
  • isExplicitQosEnabled()
  • javax.jms.Message#DEFAULT_TIME_TO_LIVE
  • javax.jms.MessageProducer#send(javax.jms.Message, int, int, long)

Protected Methods

protected QueueBrowser createBrowser (Session session, Queue queue, String messageSelector)

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.

Parameters
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)
Returns
  • the new JMS QueueBrowser
Throws
if thrown by JMS API methods
JMSException

protected MessageConsumer createConsumer (Session session, Destination destination, String messageSelector)

Create a JMS MessageConsumer for the given Session and Destination.

This implementation uses JMS 1.1 API.

Parameters
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)
Returns
  • the new JMS MessageConsumer
Throws
if thrown by JMS API methods
JMSException

protected MessageProducer createProducer (Session session, Destination destination)

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.

Parameters
session the JMS Session to create a MessageProducer for
destination the JMS Destination to create a MessageProducer for
Returns
  • the new JMS MessageProducer
Throws
if thrown by JMS API methods
JMSException

protected Object doConvertFromMessage (Message message)

Extract the content from the given JMS message.

Parameters
message the JMS Message to convert (can be null)
Returns
  • the content of the message, or null if none

protected MessageProducer doCreateProducer (Session session, Destination destination)

Create a raw JMS MessageProducer for the given Session and Destination.

This implementation uses JMS 1.1 API.

Parameters
session the JMS Session to create a MessageProducer for
destination the JMS Destination to create a MessageProducer for
Returns
  • the new JMS MessageProducer
Throws
if thrown by JMS API methods
JMSException

protected Message doReceive (Session session, Destination destination, String messageSelector)

Receive a JMS message.

Parameters
session the JMS Session to operate on
destination the JMS Destination to receive from
messageSelector the message selector for this consumer (can be null)
Returns
  • the JMS Message received, or null if none
Throws
if thrown by JMS API methods
JMSException

protected Message doReceive (Session session, MessageConsumer consumer)

Actually receive a JMS message.

Parameters
session the JMS Session to operate on
consumer the JMS MessageConsumer to receive with
Returns
  • the JMS Message received, or null if none
Throws
if thrown by JMS API methods
JMSException

protected void doSend (MessageProducer producer, Message message)

Actually send the given JMS message.

Parameters
producer the JMS MessageProducer to send with
message the JMS Message to send
Throws
if thrown by JMS API methods
JMSException

protected void doSend (Session session, Destination destination, MessageCreator messageCreator)

Send the given JMS message.

Parameters
session the JMS Session to operate on
destination the JMS Destination to send to
messageCreator callback to create a JMS Message
Throws
if thrown by JMS API methods
JMSException

protected Connection getConnection (JmsResourceHolder holder)

Fetch an appropriate Connection from the given JmsResourceHolder.

This implementation accepts any JMS 1.1 Connection.

Parameters
holder the JmsResourceHolder
Returns
  • an appropriate Connection fetched from the holder, or null if none found

protected Session getSession (JmsResourceHolder holder)

Fetch an appropriate Session from the given JmsResourceHolder.

This implementation accepts any JMS 1.1 Session.

Parameters
holder the JmsResourceHolder
Returns
  • an appropriate Session fetched from the holder, or null if none found

protected void initDefaultStrategies ()

Initialize the default implementations for the template's strategies: DynamicDestinationResolver and SimpleMessageConverter.

protected boolean isSessionLocallyTransacted (Session 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.

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.

Parameters
session the Session to check
Returns
  • whether the given Session is locally transacted