站内搜索: 请输入搜索关键词
当前页面: 在线文档首页 > Spring Framework 1.2.9 API 文档英文版

JmsTemplate (Spring Framework) - Spring Framework 1.2.9 API 文档英文版


org.springframework.jms.core
Class JmsTemplate

java.lang.Object
  extended by org.springframework.jms.support.JmsAccessor
      extended by org.springframework.jms.support.destination.JmsDestinationAccessor
          extended by org.springframework.jms.core.JmsTemplate
All Implemented Interfaces:
InitializingBean, JmsOperations
Direct Known Subclasses:
JmsTemplate102

public class JmsTemplate
extends JmsDestinationAccessor
implements JmsOperations

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:
JmsAccessor.setConnectionFactory(javax.jms.ConnectionFactory), JmsDestinationAccessor.setPubSubDomain(boolean), JmsTemplate102, JmsDestinationAccessor.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.
 
Fields inherited from class org.springframework.jms.support.JmsAccessor
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 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  Connection createConnection()
          Create a JMS Connection via this template's ConnectionFactory.
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)
          Extract the content from the given JMS 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, String messageSelector)
          Receive a JMS message.
protected  Message doReceive(Session session, MessageConsumer consumer)
          Actually receive a JMS message.
protected  void doSend(MessageProducer producer, Message message)
          Actually send the given JMS message.
protected  void doSend(Session session, Destination destination, MessageCreator messageCreator)
          Send the given JMS message.
 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.
 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.
 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)
          Return whether the Session is in client acknowledge mode.
 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(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.
 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 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.
 void setTimeToLive(long timeToLive)
          Set the time-to-live of the message when sending.
 
Methods inherited from class org.springframework.jms.support.destination.JmsDestinationAccessor
getDestinationResolver, isPubSubDomain, resolveDestinationName, setDestinationResolver, setPubSubDomain
 
Methods inherited from class org.springframework.jms.support.JmsAccessor
afterPropertiesSet, convertJmsAccessException, getConnectionFactory, getSessionAcknowledgeMode, isSessionTransacted, setConnectionFactory, setSessionAcknowledgeMode, setSessionAcknowledgeModeName, setSessionTransacted
 
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
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:
JmsAccessor.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:
JmsDestinationAccessor.setDestinationResolver(org.springframework.jms.support.destination.DestinationResolver), setMessageConverter(org.springframework.jms.support.converter.MessageConverter), DynamicDestinationResolver, SimpleMessageConverter

setDefaultDestination

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.

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

getDefaultDestination

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


setDefaultDestinationName

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

See Also:
send(MessageCreator), convertAndSend(Object), convertAndSend(Object, MessagePostProcessor), JmsDestinationAccessor.setDestinationResolver(org.springframework.jms.support.destination.DestinationResolver), setDefaultDestination(javax.jms.Destination)

getDefaultDestinationName

public String getDefaultDestinationName()
Return the destination name to be used on send/receive operations that do not have a destination parameter.


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)

setDeliveryPersistent

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:
setDeliveryMode(int), DeliveryMode.PERSISTENT, DeliveryMode.NON_PERSISTENT

setDeliveryMode

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(), DeliveryMode.PERSISTENT, DeliveryMode.NON_PERSISTENT, 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.


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 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
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
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:
JMSException - if thrown by JMS API methods

doSend

protected void doSend(MessageProducer producer,
                      Message message)
               throws JMSException
Actually send the given JMS message.

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

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,
                            String messageSelector)
                     throws JMSException
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)
Throws:
JMSException - if thrown by JMS API methods

doReceive

protected Message doReceive(Session session,
                            MessageConsumer consumer)
                     throws JMSException
Actually receive a JMS message.

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

isClientAcknowledge

protected boolean isClientAcknowledge(Session session)
                               throws JMSException
Return whether the Session is in client acknowledge mode.

This implementation uses JMS 1.1 API.

Parameters:
session - the JMS Session to check
Throws:
JMSException - if thrown by JMS API methods

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)
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

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,
                                         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
messageSelector - the message selector for this consumer (can be null)
Returns:
the new JMS MessageConsumer
Throws:
JMSException - if thrown by JMS API methods


Copyright (c) 2002-2007 The Spring Framework Project.