org.springframework.jms.core
Class JmsTemplate

java.lang.Object
  extended byorg.springframework.jms.core.JmsTemplate
All Implemented Interfaces:
InitializingBean, JmsOperations
Direct Known Subclasses:
JmsTemplate102

public class JmsTemplate
extends Object
implements JmsOperations, InitializingBean

Helper class that simplifies JMS access code. This class requires a JMS >= 1.1 provider, because it builds on the domain-independent API. Use the JmsTemplate102 subclass for JMS 1.0.2 providers.

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.

This template uses a DynamicDestinationResolver and a SimpleMessageConverter as default strategies for resolving a destination name or converting a message, respectively.

Since:
1.1
Author:
Mark Pollack, Juergen Hoeller
See Also:
setConnectionFactory(javax.jms.ConnectionFactory), setPubSubDomain(boolean), JmsTemplate102, setDestinationResolver(org.springframework.jms.support.destination.DestinationResolver), setMessageConverter(org.springframework.jms.support.converter.MessageConverter), DynamicDestinationResolver, SimpleMessageConverter, Destination, Session, MessageProducer, MessageConsumer

Field Summary
static long DEFAULT_RECEIVE_TIMEOUT
          Default timeout for receive operations: -1 indicates a blocking receive without timeout.
protected  Log logger
           
 
Constructor Summary
JmsTemplate()
          Create a new JmsTemplate for bean-style usage.
JmsTemplate(ConnectionFactory connectionFactory)
          Create a new JmsTemplate, given a ConnectionFactory.
 
Method Summary
 void afterPropertiesSet()
          Invoked by a BeanFactory after it has set all bean properties supplied (and satisfied BeanFactoryAware and ApplicationContextAware).
 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(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(Object message)
          Send the given object to the default destination, converting the object to a JMS message with a configured MessageConverter.
 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(String destinationName, Object message)
          Send the given object to the specified destination, converting the object to a JMS message with a configured MessageConverter.
 void convertAndSend(String destinationName, Object message, MessagePostProcessor postProcessor)
          Send the given object to the specified destination, converting the object to a JMS message with a configured MessageConverter.
protected  JmsException convertJmsAccessException(JMSException ex)
          Convert the specified checked JMSException to a Spring runtime JmsException equivalent.
protected  Connection createConnection()
          Create a JMS Connection via this template's ConnectionFactory.
protected  MessageConsumer createConsumer(Session session, Destination destination)
          Create a JMS MessageConsumer for the given Session and Destination.
protected  MessageConsumer createConsumer(Session session, Destination destination, String messageSelector)
          Create a JMS MessageConsumer for the given Session and Destination.
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).
protected  Session createSession(Connection con)
          Create a JMS Session for the given Connection.
protected  Object doConvertFromMessage(Message message)
           
protected  MessageProducer doCreateProducer(Session session, Destination destination)
          Create a raw JMS MessageProducer for the given Session and Destination.
protected  Message doReceive(Session session, Destination destination)
           
protected  Message doReceive(Session session, MessageConsumer consumer)
           
protected  Message doReceiveSelected(Session session, Destination destination, String messageSelector)
           
protected  void doSend(MessageProducer producer, Message message)
           
protected  void doSend(Session session, Destination destination, MessageCreator messageCreator)
           
 Object execute(ProducerCallback action)
          Send a message to a JMS destination.
 Object execute(SessionCallback action)
          Execute the action specified by the given action object within a JMS Session.
 Object execute(SessionCallback action, boolean startConnection)
          Execute the action specified by the given action object within a JMS Session.
 ConnectionFactory getConnectionFactory()
          Return the connection factory used for obtaining JMS connections.
 Destination getDefaultDestination()
          Return the destination to be used on send operations that do not have a destination parameter.
 int getDeliveryMode()
          Return the delivery mode to use when sending a message.
 DestinationResolver getDestinationResolver()
          Get the destination resolver for this template.
 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.
 int getSessionAcknowledgeMode()
          Return the acknowledgement mode for JMS sessions.
 long getTimeToLive()
          Return the time-to-live of the message when sending.
protected  void initDefaultStrategies()
          Initialize the default implementations for the template's strategies: DynamicDestinationResolver and SimpleMessageConverter.
protected  boolean isClientAcknowledge(Session session)
           
 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 isPubSubDomain()
          Return whether the Publish/Subscribe domain (Topics) is used.
 boolean isPubSubNoLocal()
          Return whether to inhibit the delivery of messages published by its own connection.
 boolean isSessionTransacted()
          Return whether the JMS sessions used for sending a message are transacted.
 Message receive()
          Receive a message synchronously from the default 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.
 Message receive(String destinationName)
          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.
 Object receiveAndConvert(String destinationName)
          Receive a message synchronously from the specified 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.
 Message receiveSelected(String messageSelector)
          Receive a message synchronously from the default 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.
 Object receiveSelectedAndConvert(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(String destinationName, String messageSelector)
          Receive a message synchronously from the specified destination, but only wait up to a specified time for delivery.
protected  Destination resolveDestinationName(Session session, String destinationName)
          Resolve the given destination name into a JMS Destination, via this template's DestinationResolver.
 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 send(String destinationName, MessageCreator messageCreator)
          Send a message to the specified destination.
 void setConnectionFactory(ConnectionFactory connectionFactory)
          Set the connection factory used for obtaining JMS connections.
 void setDefaultDestination(Destination destination)
          Set the destination to be used on send operations that do not have a destination parameter.
 void setDeliveryMode(int deliveryMode)
          Set the delivery mode to use when sending a message.
 void setDestinationResolver(DestinationResolver destinationResolver)
          Set the destination resolver for this template.
 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 setPubSubDomain(boolean pubSubDomain)
          Configure the JmsTemplate with knowledge of the JMS domain used.
 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.
 void setSessionAcknowledgeMode(int sessionAcknowledgeMode)
          Set the JMS acknowledgement mode that is used when creating a JMS session to send a message.
 void setSessionAcknowledgeModeName(String constantName)
          Set the JMS acknowledgement mode by the name of the corresponding constant in the JMS Session interface, e.g.
 void setSessionTransacted(boolean sessionTransacted)
          Set the transaction mode that is used when creating a JMS session to send a message.
 void setTimeToLive(long timeToLive)
          Set the time-to-live of the message when sending.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DEFAULT_RECEIVE_TIMEOUT

public static final long DEFAULT_RECEIVE_TIMEOUT
Default timeout for receive operations: -1 indicates a blocking receive without timeout.

See Also:
Constant Field Values

logger

protected final Log logger
Constructor Detail

JmsTemplate

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.

See Also:
setConnectionFactory(javax.jms.ConnectionFactory)

JmsTemplate

public JmsTemplate(ConnectionFactory connectionFactory)
Create a new JmsTemplate, given a ConnectionFactory.

Parameters:
connectionFactory - the ConnectionFactory to obtain connections from
Method Detail

initDefaultStrategies

protected void initDefaultStrategies()
Initialize the default implementations for the template's strategies: DynamicDestinationResolver and SimpleMessageConverter.

See Also:
setDestinationResolver(org.springframework.jms.support.destination.DestinationResolver), setMessageConverter(org.springframework.jms.support.converter.MessageConverter), DynamicDestinationResolver, SimpleMessageConverter

setConnectionFactory

public void setConnectionFactory(ConnectionFactory connectionFactory)
Set the connection factory used for obtaining JMS connections.


getConnectionFactory

public ConnectionFactory getConnectionFactory()
Return the connection factory used for obtaining JMS connections.


setPubSubDomain

public void setPubSubDomain(boolean pubSubDomain)
Configure the JmsTemplate with knowledge of the JMS domain used. Default is Point-to-Point (Queues).

For JmsTemplate102, this tells the JMS provider which class hierarchy to use in the implementation of the various execute methods. For JmsTemplate itself, it does not affect execute methods. In both implementations, it tells what type of destination to create if dynamic destinations are enabled.

Parameters:
pubSubDomain - true for Publish/Subscribe domain (Topics), false for Point-to-Point domain (Queues)
See Also:
setDestinationResolver(org.springframework.jms.support.destination.DestinationResolver)

isPubSubDomain

public boolean isPubSubDomain()
Return whether the Publish/Subscribe domain (Topics) is used. Otherwise, the Point-to-Point domain (Queues) is used.


setSessionTransacted

public void setSessionTransacted(boolean sessionTransacted)
Set the transaction mode that is used when creating a JMS session to send a message.

Note that that within a JTA transaction, the parameters to createSession(boolean transacted, int acknowledgeMode) method are not taken into account. Depending on the J2EE transaction context, the container makes its own decisions on these values. See section 17.3.5 of the EJB Spec.

Parameters:
sessionTransacted - the transaction mode
See Also:
Connection.createSession(boolean, int)

isSessionTransacted

public boolean isSessionTransacted()
Return whether the JMS sessions used for sending a message are transacted.


setSessionAcknowledgeModeName

public void setSessionAcknowledgeModeName(String constantName)
Set the JMS acknowledgement mode by the name of the corresponding constant in the JMS Session interface, e.g. "CLIENT_ACKNOWLEDGE".

Parameters:
constantName - name of the constant
See Also:
Session.AUTO_ACKNOWLEDGE, Session.CLIENT_ACKNOWLEDGE, Session.DUPS_OK_ACKNOWLEDGE, Connection.createSession(boolean, int)

setSessionAcknowledgeMode

public void setSessionAcknowledgeMode(int sessionAcknowledgeMode)
Set the JMS acknowledgement mode that is used when creating a JMS session to send a message. Vendor extensions to the acknowledgment mode can be set here as well.

Note that that inside an EJB the parameters to create(Queue|Topic)Session(boolean transacted, int acknowledgeMode) method are not taken into account. Depending on the transaction context in the EJB, the container makes its own decisions on these values. See section 17.3.5 of the EJB Spec.

Parameters:
sessionAcknowledgeMode - the acknowledgement mode
See Also:
Session.AUTO_ACKNOWLEDGE, Session.CLIENT_ACKNOWLEDGE, Session.DUPS_OK_ACKNOWLEDGE, Connection.createSession(boolean, int)

getSessionAcknowledgeMode

public int getSessionAcknowledgeMode()
Return the acknowledgement mode for JMS sessions.


setDefaultDestination

public void setDefaultDestination(Destination destination)
Set the destination to be used on send operations that do not have a destination parameter.

See Also:
send(MessageCreator), convertAndSend(Object), convertAndSend(Object, MessagePostProcessor)

getDefaultDestination

public Destination getDefaultDestination()
Return the destination to be used on send operations that do not have a destination parameter.


setDestinationResolver

public void setDestinationResolver(DestinationResolver destinationResolver)
Set the destination resolver for this template. Used to resolve destination names and to support dynamic destination functionality.

The default resolver is a DynamicDestinationResolver. Specify a JndiDestinationResolver for resolving destination names as JNDI locations.

See Also:
DynamicDestinationResolver, JndiDestinationResolver

getDestinationResolver

public DestinationResolver getDestinationResolver()
Get the destination resolver for this template.


setMessageConverter

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.

See Also:
convertAndSend(java.lang.Object), receiveAndConvert(), SimpleMessageConverter

getMessageConverter

public MessageConverter getMessageConverter()
Return the message converter for this template.


setMessageIdEnabled

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:
MessageProducer.setDisableMessageID(boolean)

isMessageIdEnabled

public boolean isMessageIdEnabled()
Return whether message IDs are enabled.


setMessageTimestampEnabled

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:
MessageProducer.setDisableMessageTimestamp(boolean)

isMessageTimestampEnabled

public boolean isMessageTimestampEnabled()
Return whether message timestamps are enabled.


setPubSubNoLocal

public void setPubSubNoLocal(boolean pubSubNoLocal)
Set whether to inhibit the delivery of messages published by its own connection. Default is false.

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

isPubSubNoLocal

public boolean isPubSubNoLocal()
Return whether to inhibit the delivery of messages published by its own connection.


setReceiveTimeout

public void setReceiveTimeout(long receiveTimeout)
Set the timeout to use for receive calls. The default is -1, which means no timeout.

See Also:
MessageConsumer.receive(long), MessageConsumer.receive()

getReceiveTimeout

public long getReceiveTimeout()
Return the timeout to use for receive calls.


setExplicitQosEnabled

public void setExplicitQosEnabled(boolean explicitQosEnabled)
Set if the QOS values (deliveryMode, priority, timeToLive) should be used for sending a message.

See Also:
setDeliveryMode(int), setPriority(int), setTimeToLive(long)

isExplicitQosEnabled

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)
See Also:
setDeliveryMode(int), setPriority(int), setTimeToLive(long)

setDeliveryMode

public void setDeliveryMode(int deliveryMode)
Set the delivery mode to use when sending a message.

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(), Message.DEFAULT_DELIVERY_MODE, MessageProducer.send(javax.jms.Message, int, int, long)

getDeliveryMode

public int getDeliveryMode()
Return the delivery mode to use when sending a message.


setPriority

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(), Message.DEFAULT_PRIORITY, MessageProducer.send(javax.jms.Message, int, int, long)

getPriority

public int getPriority()
Return the priority of a message when sending.


setTimeToLive

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(), Message.DEFAULT_TIME_TO_LIVE, MessageProducer.send(javax.jms.Message, int, int, long)

getTimeToLive

public long getTimeToLive()
Return the time-to-live of the message when sending.


afterPropertiesSet

public void afterPropertiesSet()
Description copied from interface: InitializingBean
Invoked by a BeanFactory after it has set all bean properties supplied (and satisfied BeanFactoryAware and ApplicationContextAware).

This method allows the bean instance to perform initialization only possible when all bean properties have been set and to throw an exception in the event of misconfiguration.

Specified by:
afterPropertiesSet in interface InitializingBean

resolveDestinationName

protected Destination resolveDestinationName(Session session,
                                             String destinationName)
                                      throws JMSException
Resolve the given destination name into a JMS Destination, via this template's DestinationResolver.

Parameters:
session - the current JMS Session
destinationName - the name of the destination
Returns:
the located Destination
Throws:
JMSException - if resolution failed
See Also:
setDestinationResolver(org.springframework.jms.support.destination.DestinationResolver)

convertJmsAccessException

protected JmsException convertJmsAccessException(JMSException ex)
Convert the specified checked JMSException to a Spring runtime JmsException equivalent.

Default implementation delegates to JmsUtils.

Parameters:
ex - the original checked JMSException to convert
Returns:
the Spring runtime JmsException wrapping ex
See Also:
JmsUtils.convertJmsAccessException(javax.jms.JMSException)

createConnection

protected Connection createConnection()
                               throws JMSException
Create a JMS Connection via this template's ConnectionFactory.

This implementation uses JMS 1.1 API.

Returns:
the new JMS Connection
Throws:
JMSException - if thrown by JMS API methods

createSession

protected Session createSession(Connection con)
                         throws JMSException
Create a JMS Session for the given Connection.

This implementation uses JMS 1.1 API.

Parameters:
con - the JMS Connection to create a Session for
Returns:
the new JMS Session
Throws:
JMSException - if thrown by JMS API methods

createProducer

protected MessageProducer createProducer(Session session,
                                         Destination destination)
                                  throws 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 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:
JMSException - if thrown by JMS API methods
See Also:
doCreateProducer(javax.jms.Session, javax.jms.Destination), setMessageIdEnabled(boolean), setMessageTimestampEnabled(boolean)

doCreateProducer

protected MessageProducer doCreateProducer(Session session,
                                           Destination destination)
                                    throws JMSException
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:
JMSException - if thrown by JMS API methods

createConsumer

protected MessageConsumer createConsumer(Session session,
                                         Destination destination)
                                  throws JMSException
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
Returns:
the new JMS MessageConsumer
Throws:
JMSException - if thrown by JMS API methods

createConsumer

protected MessageConsumer createConsumer(Session session,
                                         Destination destination,
                                         String messageSelector)
                                  throws JMSException
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
Returns:
the new JMS MessageConsumer
Throws:
JMSException - if thrown by JMS API methods

execute

public Object execute(SessionCallback action,
                      boolean startConnection)
               throws JmsException
Execute the action specified by the given action object within a JMS Session. Generalized version of execute(SessionCallback), allowing to start the JMS Connection on the fly.

Use execute(SessionCallback) for the general case. Starting the JMS Connection is just necessary for receiving messages, which is preferably achieve through the receive methods.

Parameters:
action - callback object that exposes the session
Returns:
the result object from working with the session
Throws:
JmsException - if there is any problem
See Also:
execute(SessionCallback), receive()

execute

public Object execute(SessionCallback action)
               throws JmsException
Description copied from interface: JmsOperations
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.

Note: The value of isPubSubDomain affects the behavior of this method. If isPubSubDomain equals true, then a TopicSession is passed to the callback. If false, then a QueueSession is passed to the callback.

Specified by:
execute in interface JmsOperations
Parameters:
action - callback object that exposes the session
Returns:
the result object from working with the session
Throws:
JmsException - if there is any problem

execute

public Object execute(ProducerCallback action)
               throws JmsException
Description copied from interface: JmsOperations
Send a message to a JMS destination. The callback gives access to the JMS session and MessageProducer in order to do more complex send operations.

Specified by:
execute in interface JmsOperations
Parameters:
action - callback object that exposes the session/producer pair
Returns:
the result object from working with the session
Throws:
JmsException - checked JMSException converted to unchecked

send

public void send(MessageCreator messageCreator)
          throws JmsException
Description copied from interface: JmsOperations
Send a message to the default destination.

This will only work with a default destination specified!

Specified by:
send in interface JmsOperations
Parameters:
messageCreator - callback to create a message.
Throws:
JmsException - checked JMSException converted to unchecked

send

public void send(Destination destination,
                 MessageCreator messageCreator)
          throws JmsException
Description copied from interface: JmsOperations
Send a message to the specified destination. The MessageCreator callback creates the message given a Session.

Specified by:
send in interface JmsOperations
Parameters:
destination - the destination to send this message to
messageCreator - callback to create a message.
Throws:
JmsException - checked JMSException converted to unchecked

send

public void send(String destinationName,
                 MessageCreator messageCreator)
          throws JmsException
Description copied from interface: JmsOperations
Send a message to the specified destination. The MessageCreator callback creates the message given a Session.

Specified by:
send in interface JmsOperations
Parameters:
destinationName - the name of the destination to send this message to (to be resolved to an actual destination by a DestinationResolver)
messageCreator - callback to create a message.
Throws:
JmsException - checked JMSException converted to unchecked

doSend

protected void doSend(Session session,
                      Destination destination,
                      MessageCreator messageCreator)
               throws JMSException
Throws:
JMSException

doSend

protected void doSend(MessageProducer producer,
                      Message message)
               throws JMSException
Throws:
JMSException

convertAndSend

public void convertAndSend(Object message)
                    throws JmsException
Description copied from interface: JmsOperations
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!

Specified by:
convertAndSend in interface JmsOperations
Parameters:
message - the object to convert to a message
Throws:
JmsException - converted checked JMSException to unchecked

convertAndSend

public void convertAndSend(Destination destination,
                           Object message)
                    throws JmsException
Description copied from interface: JmsOperations
Send the given object to the specified destination, converting the object to a JMS message with a configured MessageConverter.

Specified by:
convertAndSend in interface JmsOperations
Parameters:
destination - the destination to send this message to
message - the object to convert to a message
Throws:
JmsException - converted checked JMSException to unchecked

convertAndSend

public void convertAndSend(String destinationName,
                           Object message)
                    throws JmsException
Description copied from interface: JmsOperations
Send the given object to the specified destination, converting the object to a JMS message with a configured MessageConverter.

Specified by:
convertAndSend in interface JmsOperations
Parameters:
destinationName - the name of the destination to send this message to (to be resolved to an actual destination by a DestinationResolver)
message - the object to convert to a message
Throws:
JmsException - checked JMSException converted to unchecked

convertAndSend

public void convertAndSend(Object message,
                           MessagePostProcessor postProcessor)
                    throws JmsException
Description copied from interface: JmsOperations
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!

Specified by:
convertAndSend in interface JmsOperations
Parameters:
message - the object to convert to a message
postProcessor - the callback to modify the message
Throws:
JmsException - checked JMSException converted to unchecked

convertAndSend

public void convertAndSend(Destination destination,
                           Object message,
                           MessagePostProcessor postProcessor)
                    throws JmsException
Description copied from interface: JmsOperations
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.

Specified by:
convertAndSend in interface JmsOperations
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 - checked JMSException converted to unchecked

convertAndSend

public void convertAndSend(String destinationName,
                           Object message,
                           MessagePostProcessor postProcessor)
                    throws JmsException
Description copied from interface: JmsOperations
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.

Specified by:
convertAndSend in interface JmsOperations
Parameters:
destinationName - the name of the destination to send this message to (to be resolved to an actual destination by a DestinationResolver)
message - the object to convert to a message.
postProcessor - the callback to modify the message
Throws:
JmsException - checked JMSException converted to unchecked

receive

public Message receive()
                throws JmsException
Description copied from interface: JmsOperations
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!

Specified by:
receive in interface JmsOperations
Returns:
the message produced for the consumer or null if the timeout expires.
Throws:
JmsException - checked JMSException converted to unchecked

receive

public Message receive(Destination destination)
                throws JmsException
Description copied from interface: JmsOperations
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.

Specified by:
receive in interface JmsOperations
Parameters:
destination - the destination to receive a message from
Returns:
the message produced for the consumer or null if the timeout expires.
Throws:
JmsException - checked JMSException converted to unchecked

receive

public Message receive(String destinationName)
                throws JmsException
Description copied from interface: JmsOperations
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.

Specified by:
receive in interface JmsOperations
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 produced for the consumer or null if the timeout expires.
Throws:
JmsException - checked JMSException converted to unchecked

receiveSelected

public Message receiveSelected(String messageSelector)
                        throws JmsException
Description copied from interface: JmsOperations
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!

Specified by:
receiveSelected in interface JmsOperations
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 - checked JMSException converted to unchecked

receiveSelected

public Message receiveSelected(Destination destination,
                               String messageSelector)
                        throws JmsException
Description copied from interface: JmsOperations
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.

Specified by:
receiveSelected in interface JmsOperations
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 - checked JMSException converted to unchecked

receiveSelected

public Message receiveSelected(String destinationName,
                               String messageSelector)
                        throws JmsException
Description copied from interface: JmsOperations
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.

Specified by:
receiveSelected in interface JmsOperations
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 produced for the consumer or null if the timeout expires.
Throws:
JmsException - checked JMSException converted to unchecked

doReceive

protected Message doReceive(Session session,
                            Destination destination)
                     throws JMSException
Throws:
JMSException

doReceiveSelected

protected Message doReceiveSelected(Session session,
                                    Destination destination,
                                    String messageSelector)
                             throws JMSException
Throws:
JMSException

doReceive

protected Message doReceive(Session session,
                            MessageConsumer consumer)
                     throws JMSException
Throws:
JMSException

isClientAcknowledge

protected boolean isClientAcknowledge(Session session)
                               throws JMSException
Throws:
JMSException

receiveAndConvert

public Object receiveAndConvert()
                         throws JmsException
Description copied from interface: JmsOperations
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!

Specified by:
receiveAndConvert in interface JmsOperations
Returns:
the message produced for the consumer or null if the timeout expires.
Throws:
JmsException - checked JMSException converted to unchecked

receiveAndConvert

public Object receiveAndConvert(Destination destination)
                         throws JmsException
Description copied from interface: JmsOperations
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.

Specified by:
receiveAndConvert in interface JmsOperations
Parameters:
destination - the destination to receive a message from
Returns:
the message produced for the consumer or null if the timeout expires.
Throws:
JmsException - checked JMSException converted to unchecked

receiveAndConvert

public Object receiveAndConvert(String destinationName)
                         throws JmsException
Description copied from interface: JmsOperations
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.

Specified by:
receiveAndConvert in interface JmsOperations
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 produced for the consumer or null if the timeout expires.
Throws:
JmsException - checked JMSException converted to unchecked

receiveSelectedAndConvert

public Object receiveSelectedAndConvert(String messageSelector)
                                 throws JmsException
Description copied from interface: JmsOperations
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!

Specified by:
receiveSelectedAndConvert in interface JmsOperations
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 - checked JMSException converted to unchecked

receiveSelectedAndConvert

public Object receiveSelectedAndConvert(Destination destination,
                                        String messageSelector)
                                 throws JmsException
Description copied from interface: JmsOperations
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.

Specified by:
receiveSelectedAndConvert in interface JmsOperations
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 - checked JMSException converted to unchecked

receiveSelectedAndConvert

public Object receiveSelectedAndConvert(String destinationName,
                                        String messageSelector)
                                 throws JmsException
Description copied from interface: JmsOperations
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.

Specified by:
receiveSelectedAndConvert in interface JmsOperations
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 produced for the consumer or null if the timeout expires.
Throws:
JmsException - checked JMSException converted to unchecked

doConvertFromMessage

protected Object doConvertFromMessage(Message message)


Copyright (C) 2003-2004 The Spring Framework Project.