| org.springframework.jms.support.destination.JmsDestinationAccessor org.springframework.jms.core.JmsTemplate
All known Subclasses: org.springframework.jms.core.JmsTemplate102,
JmsTemplate | public class JmsTemplate extends JmsDestinationAccessor implements JmsOperations(Code) | | Helper class that simplifies synchronous JMS access code.
NOTE: This class requires a JMS 1.1+ provider because it builds
on the domain-independent API. Use the
JmsTemplate102 subclass
for a JMS 1.0.2 provider, e.g. when running on a J2EE 1.3 server.
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
org.springframework.jms.support.destination.DynamicDestinationResolver and a
org.springframework.jms.support.converter.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.
author: Mark Pollack author: Juergen Hoeller since: 1.1 See Also: JmsTemplate.setConnectionFactory See Also: JmsTemplate.setPubSubDomain See Also: JmsTemplate.setDestinationResolver See Also: JmsTemplate.setMessageConverter See Also: JmsTemplate102 See Also: javax.jms.MessageProducer See Also: javax.jms.MessageConsumer |
Field Summary | |
final public static long | RECEIVE_TIMEOUT_INDEFINITE_WAIT Timeout value indicating a blocking receive without timeout. | final public static long | RECEIVE_TIMEOUT_NO_WAIT Timeout value indicating that a receive operation should
check if a message is immediately available without blocking. |
Constructor Summary | |
public | JmsTemplate() Create a new JmsTemplate for bean-style usage. | public | JmsTemplate(ConnectionFactory connectionFactory) Create a new JmsTemplate, given a ConnectionFactory. |
Method Summary | |
public void | convertAndSend(Object message) | public void | convertAndSend(Destination destination, Object message) | public void | convertAndSend(String destinationName, Object message) | public void | convertAndSend(Object message, MessagePostProcessor postProcessor) | public void | convertAndSend(Destination destination, Object message, MessagePostProcessor postProcessor) | public void | convertAndSend(String destinationName, Object message, MessagePostProcessor postProcessor) | 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 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(Session session, Destination destination, MessageCreator messageCreator) Send the given JMS message. | protected void | doSend(MessageProducer producer, Message message) Actually send the given JMS message. | public Object | execute(SessionCallback action, boolean startConnection) Execute the action specified by the given action object within a
JMS Session. | public Object | execute(SessionCallback action) | public Object | execute(ProducerCallback action) | protected Connection | getConnection(JmsResourceHolder holder) Fetch an appropriate Connection from the given JmsResourceHolder. | 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). | protected Session | getSession(JmsResourceHolder holder) Fetch an appropriate Session from the given JmsResourceHolder. | public 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. | public boolean | isExplicitQosEnabled() If "true", then the values of deliveryMode, priority, and timeToLive
will be used when sending a message. | 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. | 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. | public Message | receive() | public Message | receive(Destination destination) | public Message | receive(String destinationName) | public Object | receiveAndConvert() | public Object | receiveAndConvert(Destination destination) | public Object | receiveAndConvert(String destinationName) | public Message | receiveSelected(String messageSelector) | public Message | receiveSelected(Destination destination, String messageSelector) | public Message | receiveSelected(String destinationName, String messageSelector) | public Object | receiveSelectedAndConvert(String messageSelector) | public Object | receiveSelectedAndConvert(Destination destination, String messageSelector) | public Object | receiveSelectedAndConvert(String destinationName, String messageSelector) | public void | send(MessageCreator messageCreator) | public void | send(Destination destination, MessageCreator messageCreator) | public void | send(String destinationName, MessageCreator messageCreator) | public void | setDefaultDestination(Destination destination) Set the destination to be used on send/receive operations that do not
have a destination parameter. | public void | setDefaultDestinationName(String destinationName) Set the destination name to be used on send/receive operations that
do not have a destination parameter. | public void | setDeliveryMode(int deliveryMode) Set the delivery mode to use when sending a message. | public void | setDeliveryPersistent(boolean deliveryPersistent) Set whether message delivery should be persistent or non-persistent,
specified as boolean value ("true" or "false"). | 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. | public void | setMessageIdEnabled(boolean messageIdEnabled) Set whether message IDs are enabled. | public void | setMessageTimestampEnabled(boolean messageTimestampEnabled) Set whether message timestamps are enabled. | public void | setPriority(int priority) Set the priority of a message when sending. | public void | setPubSubNoLocal(boolean pubSubNoLocal) Set whether to inhibit the delivery of messages published by its own connection. | public void | setReceiveTimeout(long receiveTimeout) Set the timeout to use for receive calls (in milliseconds). | public void | setTimeToLive(long timeToLive) Set the time-to-live of the message when sending. |
RECEIVE_TIMEOUT_INDEFINITE_WAIT | final public static long RECEIVE_TIMEOUT_INDEFINITE_WAIT(Code) | | Timeout value indicating a blocking receive without timeout.
|
RECEIVE_TIMEOUT_NO_WAIT | final public static long RECEIVE_TIMEOUT_NO_WAIT(Code) | | Timeout value indicating that a receive operation should
check if a message is immediately available without blocking.
|
JmsTemplate | public JmsTemplate()(Code) | | 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: JmsTemplate.setConnectionFactory |
JmsTemplate | public JmsTemplate(ConnectionFactory connectionFactory)(Code) | | Create a new JmsTemplate, given a ConnectionFactory.
Parameters: connectionFactory - the ConnectionFactory to obtain Connections from |
createConsumer | protected MessageConsumer createConsumer(Session session, Destination destination, String messageSelector) throws JMSException(Code) | | 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 Parameters: destination - the JMS Destination to create a MessageConsumer for Parameters: messageSelector - the message selector for this consumer (can be null ) the new JMS MessageConsumer throws: JMSException - if thrown by JMS API methods |
createProducer | protected MessageProducer createProducer(Session session, Destination destination) throws JMSException(Code) | | 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 Parameters: destination - the JMS Destination to create a MessageProducer for the new JMS MessageProducer throws: JMSException - if thrown by JMS API methods See Also: JmsTemplate.doCreateProducer See Also: JmsTemplate.setMessageIdEnabled See Also: JmsTemplate.setMessageTimestampEnabled |
doConvertFromMessage | protected Object doConvertFromMessage(Message message)(Code) | | Extract the content from the given JMS message.
Parameters: message - the JMS Message to convert (can be null ) the content of the message, or null if none |
doCreateProducer | protected MessageProducer doCreateProducer(Session session, Destination destination) throws JMSException(Code) | | 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 Parameters: destination - the JMS Destination to create a MessageProducer for the new JMS MessageProducer throws: JMSException - if thrown by JMS API methods |
doReceive | protected Message doReceive(Session session, Destination destination, String messageSelector) throws JMSException(Code) | | Receive a JMS message.
Parameters: session - the JMS Session to operate on Parameters: destination - the JMS Destination to receive from Parameters: messageSelector - the message selector for this consumer (can be null ) the JMS Message received, or null if none throws: JMSException - if thrown by JMS API methods |
doReceive | protected Message doReceive(Session session, MessageConsumer consumer) throws JMSException(Code) | | Actually receive a JMS message.
Parameters: session - the JMS Session to operate on Parameters: consumer - the JMS MessageConsumer to send with the JMS Message received, or null if none throws: JMSException - if thrown by JMS API methods |
doSend | protected void doSend(Session session, Destination destination, MessageCreator messageCreator) throws JMSException(Code) | | Send the given JMS message.
Parameters: session - the JMS Session to operate on Parameters: destination - the JMS Destination to send to Parameters: 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(Code) | | Actually send the given JMS message.
Parameters: producer - the JMS MessageProducer to send with Parameters: message - the JMS Message to send throws: JMSException - if thrown by JMS API methods |
execute | public Object execute(SessionCallback action, boolean startConnection) throws JmsException(Code) | | 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 Parameters: startConnection - whether to start the Connection the result object from working with the Session throws: JmsException - if there is any problem See Also: JmsTemplate.execute(SessionCallback) See Also: JmsTemplate.receive |
getConnection | protected Connection getConnection(JmsResourceHolder holder)(Code) | | Fetch an appropriate Connection from the given JmsResourceHolder.
This implementation accepts any JMS 1.1 Connection.
Parameters: holder - the JmsResourceHolder an appropriate Connection fetched from the holder,or null if none found |
getDefaultDestination | public Destination getDefaultDestination()(Code) | | Return the destination to be used on send/receive operations that do not
have a destination parameter.
|
getDefaultDestinationName | public String getDefaultDestinationName()(Code) | | Return the destination name to be used on send/receive operations that
do not have a destination parameter.
|
getDeliveryMode | public int getDeliveryMode()(Code) | | Return the delivery mode to use when sending a message.
|
getMessageConverter | public MessageConverter getMessageConverter()(Code) | | Return the message converter for this template.
|
getPriority | public int getPriority()(Code) | | Return the priority of a message when sending.
|
getReceiveTimeout | public long getReceiveTimeout()(Code) | | Return the timeout to use for receive calls (in milliseconds).
|
getSession | protected Session getSession(JmsResourceHolder holder)(Code) | | Fetch an appropriate Session from the given JmsResourceHolder.
This implementation accepts any JMS 1.1 Session.
Parameters: holder - the JmsResourceHolder an appropriate Session fetched from the holder,or null if none found |
getTimeToLive | public long getTimeToLive()(Code) | | Return the time-to-live of the message when sending.
|
isExplicitQosEnabled | public boolean isExplicitQosEnabled()(Code) | | 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.
true if overriding default values of QOS parameters(deliveryMode, priority, and timeToLive) See Also: JmsTemplate.setDeliveryMode See Also: JmsTemplate.setPriority See Also: JmsTemplate.setTimeToLive |
isMessageIdEnabled | public boolean isMessageIdEnabled()(Code) | | Return whether message IDs are enabled.
|
isMessageTimestampEnabled | public boolean isMessageTimestampEnabled()(Code) | | Return whether message timestamps are enabled.
|
isPubSubNoLocal | public boolean isPubSubNoLocal()(Code) | | Return whether to inhibit the delivery of messages published by its own connection.
|
isSessionLocallyTransacted | protected boolean isSessionLocallyTransacted(Session session)(Code) | | 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 whether the given Session is locally transacted See Also: JmsTemplate.isSessionTransacted() See Also: org.springframework.jms.connection.ConnectionFactoryUtils.isSessionTransactional |
receiveSelected | public Message receiveSelected(Destination destination, String messageSelector) throws JmsException(Code) | | |
setDeliveryMode | public void setDeliveryMode(int deliveryMode)(Code) | | 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: JmsTemplate.isExplicitQosEnabled See Also: javax.jms.DeliveryMode.PERSISTENT See Also: javax.jms.DeliveryMode.NON_PERSISTENT See Also: javax.jms.Message.DEFAULT_DELIVERY_MODE See Also: javax.jms.MessageProducer.send(javax.jms.Messageintintlong) |
setDeliveryPersistent | public void setDeliveryPersistent(boolean deliveryPersistent)(Code) | | 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: JmsTemplate.setDeliveryMode(int) See Also: javax.jms.DeliveryMode.PERSISTENT See Also: javax.jms.DeliveryMode.NON_PERSISTENT |
setMessageIdEnabled | public void setMessageIdEnabled(boolean messageIdEnabled)(Code) | | 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 |
setMessageTimestampEnabled | public void setMessageTimestampEnabled(boolean messageTimestampEnabled)(Code) | | 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 |
setPriority | public void setPriority(int priority)(Code) | | 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: JmsTemplate.isExplicitQosEnabled See Also: javax.jms.Message.DEFAULT_PRIORITY See Also: javax.jms.MessageProducer.send(javax.jms.Messageintintlong) |
setPubSubNoLocal | public void setPubSubNoLocal(boolean pubSubNoLocal)(Code) | | Set whether to inhibit the delivery of messages published by its own connection.
Default is "false".
See Also: javax.jms.TopicSession.createSubscriber(javax.jms.TopicStringboolean) |
setReceiveTimeout | public void setReceiveTimeout(long receiveTimeout)(Code) | | Set the timeout to use for receive calls (in milliseconds).
The default is
JmsTemplate.RECEIVE_TIMEOUT_INDEFINITE_WAIT , which indicates
a blocking receive without timeout.
Specify
JmsTemplate.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) See Also: javax.jms.MessageConsumer.receive See Also: javax.jms.MessageConsumer.receiveNoWait |
setTimeToLive | public void setTimeToLive(long timeToLive)(Code) | | 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: JmsTemplate.isExplicitQosEnabled See Also: javax.jms.Message.DEFAULT_TIME_TO_LIVE See Also: javax.jms.MessageProducer.send(javax.jms.Messageintintlong) |
|
|