Class JmsTemplate
- All Implemented Interfaces:
InitializingBean,JmsOperations
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. Point-to-Point (Queues) is the default domain.
Default settings for JMS Sessions are "not transacted" and "auto-acknowledge". As defined by the Jakarta EE specification, the transaction and acknowledgement parameters are ignored when a JMS Session is created inside an active transaction, no matter if a JTA transaction or a Spring-managed transaction. To configure them for native JMS usage, specify appropriate values for the "sessionTransacted" and "sessionAcknowledgeMode" bean properties.
This template uses a
DynamicDestinationResolver
and a SimpleMessageConverter
as default strategies for resolving a destination name or converting a message,
respectively. These defaults can be overridden through the "destinationResolver"
and "messageConverter" bean properties.
NOTE: The ConnectionFactory used with this template should
return pooled Connections (or a single shared Connection) as well as pooled
Sessions and MessageProducers. Otherwise, performance of ad-hoc JMS operations
is going to suffer. The simplest option is to use the Spring-provided
SingleConnectionFactory as a
decorator for your target ConnectionFactory, reusing a single
JMS Connection in a thread-safe fashion; this is often good enough for the
purpose of sending messages via this template. In a Jakarta EE environment,
make sure that the ConnectionFactory is obtained from the
application's environment naming context via JNDI; application servers
typically expose pooled, transaction-aware factories there.
- Since:
- 1.1
- Author:
- Mark Pollack, Juergen Hoeller, Stephane Nicoll, Brian Clozel
- See Also:
-
JmsAccessor.setConnectionFactory(jakarta.jms.ConnectionFactory)JmsDestinationAccessor.setPubSubDomain(boolean)JmsDestinationAccessor.setDestinationResolver(org.springframework.jms.support.destination.DestinationResolver)setMessageConverter(org.springframework.jms.support.converter.MessageConverter)MessageProducerMessageConsumer
-
Field Summary
Fields inherited from class org.springframework.jms.support.destination.JmsDestinationAccessor
RECEIVE_TIMEOUT_INDEFINITE_WAIT, RECEIVE_TIMEOUT_NO_WAITFields inherited from class org.springframework.jms.support.JmsAccessor
logger -
Constructor Summary
ConstructorsConstructorDescriptionCreate a new JmsTemplate for bean-style usage.JmsTemplate(ConnectionFactory connectionFactory) Create a new JmsTemplate, given a ConnectionFactory. -
Method Summary
Modifier and TypeMethodDescription<T> Tbrowse(Queue queue, BrowserCallback<T> action) Browse messages in a JMS queue.<T> Tbrowse(String queueName, BrowserCallback<T> action) Browse messages in a JMS queue.<T> Tbrowse(BrowserCallback<T> action) Browse messages in the default JMS queue.<T> TbrowseSelected(Queue queue, String messageSelector, BrowserCallback<T> action) Browse selected messages in a JMS queue.<T> TbrowseSelected(String queueName, String messageSelector, BrowserCallback<T> action) Browse selected messages in a JMS queue.<T> TbrowseSelected(String messageSelector, BrowserCallback<T> action) Browse selected messages in a JMS queue.voidconvertAndSend(Destination destination, Object message) Send the given object to the specified destination, converting the object to a JMS message with a configured MessageConverter.voidconvertAndSend(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.voidconvertAndSend(Object message) Send the given object to the default destination, converting the object to a JMS message with a configured MessageConverter.voidconvertAndSend(Object message, MessagePostProcessor postProcessor) Send the given object to the default destination, converting the object to a JMS message with a configured MessageConverter.voidconvertAndSend(String destinationName, Object message) Send the given object to the specified destination, converting the object to a JMS message with a configured MessageConverter.voidconvertAndSend(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 QueueBrowsercreateBrowser(Session session, Queue queue, String messageSelector) Create a JMS MessageProducer for the given Session and Destination, configuring it to disable message ids and/or timestamps (if necessary).protected MessageConsumercreateConsumer(Session session, Destination destination, String messageSelector) Create a JMS MessageConsumer for the given Session and Destination.protected MessageProducercreateProducer(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 ObjectdoConvertFromMessage(Message message) Extract the content from the given JMS message.protected MessageProducerdoCreateProducer(Session session, Destination destination) Create a raw JMS MessageProducer for the given Session and Destination.protected MessagedoReceive(Session session, Destination destination, String messageSelector) Receive a JMS message.protected MessagedoReceive(Session session, MessageConsumer consumer) Actually receive a JMS message.protected voiddoSend(MessageProducer producer, Message message) Actually send the given JMS message.protected voiddoSend(Session session, Destination destination, MessageCreator messageCreator) Send the given JMS message.protected MessagedoSendAndReceive(Session session, Destination destination, MessageCreator messageCreator) Send a request message to the givenDestinationand block until a reply has been received on a temporary queue created on-the-fly.<T> Texecute(Destination destination, ProducerCallback<T> action) Send messages to a JMS destination.<T> Texecute(String destinationName, ProducerCallback<T> action) Send messages to a JMS destination.<T> Texecute(ProducerCallback<T> action) Send messages to the default JMS destination (or one specified for each send operation).<T> Texecute(SessionCallback<T> action) Execute the action specified by the given action object within a JMS Session.<T> Texecute(SessionCallback<T> action, boolean startConnection) Execute the action specified by the given action object within a JMS Session.protected ConnectiongetConnection(JmsResourceHolder holder) Fetch an appropriate Connection from the given JmsResourceHolder.Return the destination to be used on send/receive operations that do not have a destination parameter.Return the destination name to be used on send/receive operations that do not have a destination parameter.longReturn the delivery delay to use for send calls (in milliseconds).intReturn the delivery mode to use when sending a message.Return the message converter for this template.intReturn the priority of a message when sending.longReturn the timeout to use for receive calls (in milliseconds).protected SessiongetSession(JmsResourceHolder holder) Fetch an appropriate Session from the given JmsResourceHolder.longReturn the time-to-live of the message when sending.protected voidInitialize the default implementations for the template's strategies.booleanIf "true", then the values of deliveryMode, priority, and timeToLive will be used when sending a message.booleanReturn whether message IDs are enabled.booleanReturn whether message timestamps are enabled.booleanReturn whether to inhibit the delivery of messages published by its own connection.protected booleanisSessionLocallyTransacted(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.receive()Receive a message synchronously from the default destination, but only wait up to a specified time for delivery.receive(Destination destination) Receive a message synchronously from the specified destination, but only wait up to a specified time for delivery.Receive a message synchronously from the specified destination, but only wait up to a specified time for delivery.Receive a message synchronously from the default destination, but only wait up to a specified time for delivery.receiveAndConvert(Destination destination) Receive a message synchronously from the specified destination, but only wait up to a specified time for delivery.receiveAndConvert(String destinationName) Receive a message synchronously from the specified destination, but only wait up to a specified time for delivery.receiveSelected(Destination destination, String messageSelector) Receive a message synchronously from the specified destination, but only wait up to a specified time for delivery.receiveSelected(String messageSelector) Receive a message synchronously from the default destination, but only wait up to a specified time for delivery.receiveSelected(String destinationName, String messageSelector) Receive a message synchronously from the specified destination, but only wait up to a specified time for delivery.receiveSelectedAndConvert(Destination destination, String messageSelector) Receive a message synchronously from the specified destination, but only wait up to a specified time for delivery.receiveSelectedAndConvert(String messageSelector) Receive a message synchronously from the default destination, but only wait up to a specified time for delivery.receiveSelectedAndConvert(String destinationName, String messageSelector) Receive a message synchronously from the specified destination, but only wait up to a specified time for delivery.voidsend(Destination destination, MessageCreator messageCreator) Send a message to the specified destination.voidsend(String destinationName, MessageCreator messageCreator) Send a message to the specified destination.voidsend(MessageCreator messageCreator) Send a message to the default destination.sendAndReceive(Destination destination, MessageCreator messageCreator) Send a message and receive the reply from the specified destination.sendAndReceive(String destinationName, MessageCreator messageCreator) Send a message and receive the reply from the specified destination.sendAndReceive(MessageCreator messageCreator) Send a request message and receive the reply from a default destination.voidsetDefaultDestination(Destination destination) Set the destination to be used on send/receive operations that do not have a destination parameter.voidsetDefaultDestinationName(String destinationName) Set the destination name to be used on send/receive operations that do not have a destination parameter.voidsetDeliveryDelay(long deliveryDelay) Set the delivery delay to use for send calls (in milliseconds).voidsetDeliveryMode(int deliveryMode) Set the delivery mode to use when sending a message.voidsetDeliveryPersistent(boolean deliveryPersistent) Set whether message delivery should be persistent or non-persistent, specified as boolean value ("true" or "false").voidsetExplicitQosEnabled(boolean explicitQosEnabled) Set if the QOS values (deliveryMode, priority, timeToLive) should be used for sending a message.voidsetMessageConverter(MessageConverter messageConverter) Set the message converter for this template.voidsetMessageIdEnabled(boolean messageIdEnabled) Set whether message IDs are enabled.voidsetMessageTimestampEnabled(boolean messageTimestampEnabled) Set whether message timestamps are enabled.voidsetObservationRegistry(io.micrometer.observation.ObservationRegistry observationRegistry) Configure theObservationRegistryto use for recording JMS observations.voidsetPriority(int priority) Set the priority of a message when sending.voidsetPubSubNoLocal(boolean pubSubNoLocal) Set whether to inhibit the delivery of messages published by its own connection.voidsetQosSettings(QosSettings settings) Set theQosSettingsto use when sending a message.voidsetReceiveTimeout(long receiveTimeout) Set the timeout to use for receive calls (in milliseconds).voidsetTimeToLive(long timeToLive) Set the time-to-live of the message when sending.Methods inherited from class org.springframework.jms.support.destination.JmsDestinationAccessor
getDestinationResolver, isPubSubDomain, receiveFromConsumer, resolveDestinationName, setDestinationResolver, setPubSubDomainMethods inherited from class org.springframework.jms.support.JmsAccessor
afterPropertiesSet, convertJmsAccessException, createConnection, createSession, getConnectionFactory, getSessionAcknowledgeMode, isClientAcknowledge, isSessionTransacted, obtainConnectionFactory, setConnectionFactory, setSessionAcknowledgeMode, setSessionAcknowledgeModeName, setSessionTransacted
-
Constructor Details
-
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.
-
JmsTemplate
Create a new JmsTemplate, given a ConnectionFactory.- Parameters:
connectionFactory- the ConnectionFactory to obtain Connections from
-
-
Method Details
-
initDefaultStrategies
protected void initDefaultStrategies()Initialize the default implementations for the template's strategies. -
setDefaultDestination
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.
-
getDefaultDestination
Return the destination to be used on send/receive operations that do not have a destination parameter. -
setDefaultDestinationName
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".
-
getDefaultDestinationName
Return the destination name to be used on send/receive operations that do not have a destination parameter. -
setMessageConverter
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.
-
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.
-
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.
-
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". -
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 (in milliseconds).The default is
JmsDestinationAccessor.RECEIVE_TIMEOUT_INDEFINITE_WAIT, which indicates a blocking receive without timeout.Specify
JmsDestinationAccessor.RECEIVE_TIMEOUT_NO_WAIT(or any other negative value) to indicate that a receive operation should check if a message is immediately available without blocking. -
getReceiveTimeout
public long getReceiveTimeout()Return the timeout to use for receive calls (in milliseconds). -
setDeliveryDelay
public void setDeliveryDelay(long deliveryDelay) Set the delivery delay to use for send calls (in milliseconds).The default is -1 (no delivery delay passed on to the broker). Note that this feature requires JMS 2.0.
-
getDeliveryDelay
public long getDeliveryDelay()Return the delivery delay to use for send calls (in milliseconds). -
setExplicitQosEnabled
public void setExplicitQosEnabled(boolean explicitQosEnabled) Set if the QOS values (deliveryMode, priority, timeToLive) should be used for sending a message. -
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:
-
setQosSettings
Set theQosSettingsto use when sending a message.- Parameters:
settings- the deliveryMode, priority, and timeToLive settings to use- Since:
- 5.0
- See Also:
-
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" (2) or "NON_PERSISTENT" (1).Default is "true" a.k.a. delivery mode "PERSISTENT".
-
setDeliveryMode
public void setDeliveryMode(int deliveryMode) Set the delivery mode to use when sending a message. Default is the JMS 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:
-
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".
-
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 lifetime (in milliseconds)- See Also:
-
getTimeToLive
public long getTimeToLive()Return the time-to-live of the message when sending. -
setObservationRegistry
public void setObservationRegistry(io.micrometer.observation.ObservationRegistry observationRegistry) Configure theObservationRegistryto use for recording JMS observations.- Parameters:
observationRegistry- the observation registry to use- Since:
- 6.1
- See Also:
-
JmsInstrumentation
-
execute
Description copied from interface:JmsOperationsExecute the action specified by the given action object within a JMS Session.- Specified by:
executein interfaceJmsOperations- 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
@Nullable public <T> T execute(SessionCallback<T> action, boolean startConnection) throws JmsException Execute the action specified by the given action object within a JMS Session. Generalized version ofexecute(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 thereceivemethods.- Parameters:
action- callback object that exposes the SessionstartConnection- whether to start the Connection- Returns:
- the result object from working with the Session
- Throws:
JmsException- if there is any problem- See Also:
-
execute
Description copied from interface:JmsOperationsSend messages to the default JMS destination (or one specified for each send operation). The callback gives access to the JMS Session and MessageProducer in order to perform complex send operations.- Specified by:
executein interfaceJmsOperations- 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
-
execute
@Nullable public <T> T execute(@Nullable Destination destination, ProducerCallback<T> action) throws JmsException Description copied from interface:JmsOperationsSend messages to a JMS destination. The callback gives access to the JMS Session and MessageProducer in order to perform complex send operations.- Specified by:
executein interfaceJmsOperations- Parameters:
destination- the destination to send messages toaction- callback object that exposes the session/producer pair- Returns:
- the result object from working with the session
- Throws:
JmsException- checked JMSException converted to unchecked
-
execute
@Nullable public <T> T execute(String destinationName, ProducerCallback<T> action) throws JmsException Description copied from interface:JmsOperationsSend messages to a JMS destination. The callback gives access to the JMS Session and MessageProducer in order to perform complex send operations.- Specified by:
executein interfaceJmsOperations- Parameters:
destinationName- the name of the destination to send messages to (to be resolved to an actual destination by a DestinationResolver)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
Description copied from interface:JmsOperationsSend a message to the default destination.This will only work with a default destination specified!
- Specified by:
sendin interfaceJmsOperations- Parameters:
messageCreator- callback to create a message- Throws:
JmsException- checked JMSException converted to unchecked
-
send
Description copied from interface:JmsOperationsSend a message to the specified destination. The MessageCreator callback creates the message given a Session.- Specified by:
sendin interfaceJmsOperations- Parameters:
destination- the destination to send this message tomessageCreator- callback to create a message- Throws:
JmsException- checked JMSException converted to unchecked
-
send
Description copied from interface:JmsOperationsSend a message to the specified destination. The MessageCreator callback creates the message given a Session.- Specified by:
sendin interfaceJmsOperations- 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 ondestination- the JMS Destination to send tomessageCreator- callback to create a JMS Message- Throws:
JMSException- if thrown by JMS API methods
-
doSend
Actually send the given JMS message.- Parameters:
producer- the JMS MessageProducer to send withmessage- the JMS Message to send- Throws:
JMSException- if thrown by JMS API methods
-
convertAndSend
Description copied from interface:JmsOperationsSend 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:
convertAndSendin interfaceJmsOperations- Parameters:
message- the object to convert to a message- Throws:
JmsException- converted checked JMSException to unchecked
-
convertAndSend
Description copied from interface:JmsOperationsSend the given object to the specified destination, converting the object to a JMS message with a configured MessageConverter.- Specified by:
convertAndSendin interfaceJmsOperations- Parameters:
destination- the destination to send this message tomessage- the object to convert to a message- Throws:
JmsException- converted checked JMSException to unchecked
-
convertAndSend
Description copied from interface:JmsOperationsSend the given object to the specified destination, converting the object to a JMS message with a configured MessageConverter.- Specified by:
convertAndSendin interfaceJmsOperations- 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
Description copied from interface:JmsOperationsSend 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:
convertAndSendin interfaceJmsOperations- Parameters:
message- the object to convert to a messagepostProcessor- 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:JmsOperationsSend 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:
convertAndSendin interfaceJmsOperations- Parameters:
destination- the destination to send this message tomessage- the object to convert to a messagepostProcessor- 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:JmsOperationsSend 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:
convertAndSendin interfaceJmsOperations- 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
Description copied from interface:JmsOperationsReceive 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:
receivein interfaceJmsOperations- Returns:
- the message received by the consumer, or
nullif the timeout expires - Throws:
JmsException- checked JMSException converted to unchecked
-
receive
Description copied from interface:JmsOperationsReceive 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:
receivein interfaceJmsOperations- Parameters:
destination- the destination to receive a message from- Returns:
- the message received by the consumer, or
nullif the timeout expires - Throws:
JmsException- checked JMSException converted to unchecked
-
receive
Description copied from interface:JmsOperationsReceive 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:
receivein interfaceJmsOperations- Parameters:
destinationName- the name of the destination to send this message to (to be resolved to an actual destination by a DestinationResolver)- Returns:
- the message received by the consumer, or
nullif the timeout expires - Throws:
JmsException- checked JMSException converted to unchecked
-
receiveSelected
Description copied from interface:JmsOperationsReceive 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:
receiveSelectedin interfaceJmsOperations- Parameters:
messageSelector- the JMS message selector expression (ornullif none). See the JMS specification for a detailed definition of selector expressions.- Returns:
- the message received by the consumer, or
nullif the timeout expires - Throws:
JmsException- checked JMSException converted to unchecked
-
receiveSelected
@Nullable public Message receiveSelected(Destination destination, @Nullable String messageSelector) throws JmsException Description copied from interface:JmsOperationsReceive 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:
receiveSelectedin interfaceJmsOperations- Parameters:
destination- the destination to receive a message frommessageSelector- the JMS message selector expression (ornullif none). See the JMS specification for a detailed definition of selector expressions.- Returns:
- the message received by the consumer, or
nullif the timeout expires - Throws:
JmsException- checked JMSException converted to unchecked
-
receiveSelected
@Nullable public Message receiveSelected(String destinationName, @Nullable String messageSelector) throws JmsException Description copied from interface:JmsOperationsReceive 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:
receiveSelectedin interfaceJmsOperations- 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 (ornullif none). See the JMS specification for a detailed definition of selector expressions.- Returns:
- the message received by the consumer, or
nullif the timeout expires - Throws:
JmsException- checked JMSException converted to unchecked
-
doReceive
@Nullable protected Message doReceive(Session session, Destination destination, @Nullable String messageSelector) throws JMSException Receive a JMS message.- Parameters:
session- the JMS Session to operate ondestination- the JMS Destination to receive frommessageSelector- the message selector for this consumer (can benull)- Returns:
- the JMS Message received, or
nullif none - Throws:
JMSException- if thrown by JMS API methods
-
doReceive
@Nullable protected Message doReceive(Session session, MessageConsumer consumer) throws JMSException Actually receive a JMS message.- Parameters:
session- the JMS Session to operate onconsumer- the JMS MessageConsumer to receive with- Returns:
- the JMS Message received, or
nullif none - Throws:
JMSException- if thrown by JMS API methods
-
receiveAndConvert
Description copied from interface:JmsOperationsReceive 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:
receiveAndConvertin interfaceJmsOperations- Returns:
- the message produced for the consumer, or
nullif the timeout expires - Throws:
JmsException- checked JMSException converted to unchecked
-
receiveAndConvert
Description copied from interface:JmsOperationsReceive 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:
receiveAndConvertin interfaceJmsOperations- Parameters:
destination- the destination to receive a message from- Returns:
- the message produced for the consumer, or
nullif the timeout expires - Throws:
JmsException- checked JMSException converted to unchecked
-
receiveAndConvert
Description copied from interface:JmsOperationsReceive 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:
receiveAndConvertin interfaceJmsOperations- 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
nullif the timeout expires - Throws:
JmsException- checked JMSException converted to unchecked
-
receiveSelectedAndConvert
@Nullable public Object receiveSelectedAndConvert(@Nullable String messageSelector) throws JmsException Description copied from interface:JmsOperationsReceive 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:
receiveSelectedAndConvertin interfaceJmsOperations- Parameters:
messageSelector- the JMS message selector expression (ornullif none). See the JMS specification for a detailed definition of selector expressions.- Returns:
- the message produced for the consumer, or
nullif the timeout expires - Throws:
JmsException- checked JMSException converted to unchecked
-
receiveSelectedAndConvert
@Nullable public Object receiveSelectedAndConvert(Destination destination, @Nullable String messageSelector) throws JmsException Description copied from interface:JmsOperationsReceive 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:
receiveSelectedAndConvertin interfaceJmsOperations- Parameters:
destination- the destination to receive a message frommessageSelector- the JMS message selector expression (ornullif none). See the JMS specification for a detailed definition of selector expressions.- Returns:
- the message produced for the consumer, or
nullif the timeout expires - Throws:
JmsException- checked JMSException converted to unchecked
-
receiveSelectedAndConvert
@Nullable public Object receiveSelectedAndConvert(String destinationName, @Nullable String messageSelector) throws JmsException Description copied from interface:JmsOperationsReceive 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:
receiveSelectedAndConvertin interfaceJmsOperations- 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 (ornullif none). See the JMS specification for a detailed definition of selector expressions.- Returns:
- the message produced for the consumer, or
nullif the timeout expires - Throws:
JmsException- checked JMSException converted to unchecked
-
doConvertFromMessage
Extract the content from the given JMS message.- Parameters:
message- the JMS Message to convert (can benull)- Returns:
- the content of the message, or
nullif none
-
sendAndReceive
Description copied from interface:JmsOperationsSend a request message and receive the reply from a default destination. TheMessageCreatorcallback creates the message given a Session. A temporary queue is created as part of this operation and is set in theJMSReplyTOheader of the message.This will only work with a default destination specified!
- Specified by:
sendAndReceivein interfaceJmsOperations- Parameters:
messageCreator- callback to create a request message- Returns:
- the reply, possibly
nullif the message could not be received, for example due to a timeout - Throws:
JmsException- checked JMSException converted to unchecked
-
sendAndReceive
@Nullable public Message sendAndReceive(Destination destination, MessageCreator messageCreator) throws JmsException Description copied from interface:JmsOperationsSend a message and receive the reply from the specified destination. TheMessageCreatorcallback creates the message given a Session. A temporary queue is created as part of this operation and is set in theJMSReplyTOheader of the message.- Specified by:
sendAndReceivein interfaceJmsOperations- Parameters:
destination- the destination to send this message tomessageCreator- callback to create a message- Returns:
- the reply, possibly
nullif the message could not be received, for example due to a timeout - Throws:
JmsException- checked JMSException converted to unchecked
-
sendAndReceive
@Nullable public Message sendAndReceive(String destinationName, MessageCreator messageCreator) throws JmsException Description copied from interface:JmsOperationsSend a message and receive the reply from the specified destination. TheMessageCreatorcallback creates the message given a Session. A temporary queue is created as part of this operation and is set in theJMSReplyTOheader of the message.- Specified by:
sendAndReceivein interfaceJmsOperations- 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- Returns:
- the reply, possibly
nullif the message could not be received, for example due to a timeout - Throws:
JmsException- checked JMSException converted to unchecked
-
doSendAndReceive
@Nullable protected Message doSendAndReceive(Session session, Destination destination, MessageCreator messageCreator) throws JMSException Send a request message to the givenDestinationand block until a reply has been received on a temporary queue created on-the-fly.Return the response message or
nullif no message has- Throws:
JMSException- if thrown by JMS API methods
-
browse
Description copied from interface:JmsOperationsBrowse messages in the default JMS queue. The callback gives access to the JMS Session and QueueBrowser in order to browse the queue and react to the contents.- Specified by:
browsein interfaceJmsOperations- Parameters:
action- callback object that exposes the session/browser pair- Returns:
- the result object from working with the session
- Throws:
JmsException- checked JMSException converted to unchecked
-
browse
Description copied from interface:JmsOperationsBrowse messages in a JMS queue. The callback gives access to the JMS Session and QueueBrowser in order to browse the queue and react to the contents.- Specified by:
browsein interfaceJmsOperations- Parameters:
queue- the queue to browseaction- callback object that exposes the session/browser pair- Returns:
- the result object from working with the session
- Throws:
JmsException- checked JMSException converted to unchecked
-
browse
Description copied from interface:JmsOperationsBrowse messages in a JMS queue. The callback gives access to the JMS Session and QueueBrowser in order to browse the queue and react to the contents.- Specified by:
browsein interfaceJmsOperations- Parameters:
queueName- the name of the queue to browse (to be resolved to an actual destination by a DestinationResolver)action- callback object that exposes the session/browser pair- Returns:
- the result object from working with the session
- Throws:
JmsException- checked JMSException converted to unchecked
-
browseSelected
@Nullable public <T> T browseSelected(@Nullable String messageSelector, BrowserCallback<T> action) throws JmsException Description copied from interface:JmsOperationsBrowse selected messages in a JMS queue. The callback gives access to the JMS Session and QueueBrowser in order to browse the queue and react to the contents.- Specified by:
browseSelectedin interfaceJmsOperations- Parameters:
messageSelector- the JMS message selector expression (ornullif none). See the JMS specification for a detailed definition of selector expressions.action- callback object that exposes the session/browser pair- Returns:
- the result object from working with the session
- Throws:
JmsException- checked JMSException converted to unchecked
-
browseSelected
@Nullable public <T> T browseSelected(Queue queue, @Nullable String messageSelector, BrowserCallback<T> action) throws JmsException Description copied from interface:JmsOperationsBrowse selected messages in a JMS queue. The callback gives access to the JMS Session and QueueBrowser in order to browse the queue and react to the contents.- Specified by:
browseSelectedin interfaceJmsOperations- Parameters:
queue- the queue to browsemessageSelector- the JMS message selector expression (ornullif none). See the JMS specification for a detailed definition of selector expressions.action- callback object that exposes the session/browser pair- Returns:
- the result object from working with the session
- Throws:
JmsException- checked JMSException converted to unchecked
-
browseSelected
@Nullable public <T> T browseSelected(String queueName, @Nullable String messageSelector, BrowserCallback<T> action) throws JmsException Description copied from interface:JmsOperationsBrowse selected messages in a JMS queue. The callback gives access to the JMS Session and QueueBrowser in order to browse the queue and react to the contents.- Specified by:
browseSelectedin interfaceJmsOperations- Parameters:
queueName- the name of the queue to browse (to be resolved to an actual destination by a DestinationResolver)messageSelector- the JMS message selector expression (ornullif none). See the JMS specification for a detailed definition of selector expressions.action- callback object that exposes the session/browser pair- Returns:
- the result object from working with the session
- Throws:
JmsException- checked JMSException converted to unchecked
-
getConnection
Fetch an appropriate Connection from the given JmsResourceHolder.This implementation accepts any JMS 1.1 Connection.
- Parameters:
holder- the JmsResourceHolder- Returns:
- an appropriate Connection fetched from the holder,
or
nullif none found
-
getSession
Fetch an appropriate Session from the given JmsResourceHolder.This implementation accepts any JMS 1.1 Session.
- Parameters:
holder- the JmsResourceHolder- Returns:
- an appropriate Session fetched from the holder,
or
nullif none found
-
isSessionLocallyTransacted
Check whether the given Session is locally transacted, that is, whether its transaction is managed by this listener container's Session handling and not by an external transaction coordinator.Note: The Session's own transacted flag will already have been checked before. This method is about finding out whether the Session's transaction is local or externally coordinated.
- Parameters:
session- the Session to check- Returns:
- whether the given Session is locally transacted
- See Also:
-
createProducer
protected MessageProducer createProducer(Session session, @Nullable 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(jakarta.jms.Session, jakarta.jms.Destination)for creation of the raw JMS MessageProducer.- Parameters:
session- the JMS Session to create a MessageProducer fordestination- the JMS Destination to create a MessageProducer for- Returns:
- the new JMS MessageProducer
- Throws:
JMSException- if thrown by JMS API methods- See Also:
-
doCreateProducer
protected MessageProducer doCreateProducer(Session session, @Nullable 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 fordestination- 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, @Nullable 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 fordestination- the JMS Destination to create a MessageConsumer formessageSelector- the message selector for this consumer (can benull)- Returns:
- the new JMS MessageConsumer
- Throws:
JMSException- if thrown by JMS API methods
-
createBrowser
protected QueueBrowser createBrowser(Session session, Queue queue, @Nullable String messageSelector) 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(jakarta.jms.Session, jakarta.jms.Destination)for creation of the raw JMS MessageProducer.- Parameters:
session- the JMS Session to create a QueueBrowser forqueue- the JMS Queue to create a QueueBrowser formessageSelector- the message selector for this consumer (can benull)- Returns:
- the new JMS QueueBrowser
- Throws:
JMSException- if thrown by JMS API methods- See Also:
-