Interface JmsOperations
- All Known Implementing Classes:
JmsTemplate
Implemented by JmsTemplate
. Not often used but a useful option
to enhance testability, as it can easily be mocked or stubbed.
Provides JmsTemplate's
send(..)
and
receive(..)
methods that mirror various JMS API methods.
See the JMS specification and javadocs for details on those methods.
Provides also basic request reply operation using a temporary queue to collect the reply.
- Since:
- 1.1
- Author:
- Mark Pollack, Juergen Hoeller, Stephane Nicoll
- See Also:
-
Method Summary
Modifier and TypeMethodDescription<T> T
browse
(Queue queue, BrowserCallback<T> action) Browse messages in a JMS queue.<T> T
browse
(String queueName, BrowserCallback<T> action) Browse messages in a JMS queue.<T> T
browse
(BrowserCallback<T> action) Browse messages in the default JMS queue.<T> T
browseSelected
(Queue queue, String messageSelector, BrowserCallback<T> action) Browse selected messages in a JMS queue.<T> T
browseSelected
(String queueName, String messageSelector, BrowserCallback<T> action) Browse selected messages in a JMS queue.<T> T
browseSelected
(String messageSelector, BrowserCallback<T> action) Browse selected messages in a JMS queue.void
convertAndSend
(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.<T> T
execute
(Destination destination, ProducerCallback<T> action) Send messages to a JMS destination.<T> T
execute
(String destinationName, ProducerCallback<T> action) Send messages to a JMS destination.<T> T
execute
(ProducerCallback<T> action) Send messages to the default JMS destination (or one specified for each send operation).<T> T
execute
(SessionCallback<T> action) Execute the action specified by the given action object within a JMS Session.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.void
send
(Destination destination, MessageCreator messageCreator) Send a message to the specified destination.void
send
(String destinationName, MessageCreator messageCreator) Send a message to the specified destination.void
send
(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.
-
Method Details
-
execute
Execute the action specified by the given action object within a JMS Session.- 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
Send messages to the default JMS destination (or one specified for each send operation). The callback gives access to the JMS Session and MessageProducer in order to perform complex send operations.- Parameters:
action
- callback object that exposes the session/producer pair- Returns:
- the result object from working with the session
- Throws:
JmsException
- checked JMSException converted to unchecked
-
execute
Send messages to a JMS destination. The callback gives access to the JMS Session and MessageProducer in order to perform complex send operations.- Parameters:
destination
- the destination to send messages 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
Send messages to a JMS destination. The callback gives access to the JMS Session and MessageProducer in order to perform complex send operations.- 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
Send a message to the default destination.This will only work with a default destination specified!
- Parameters:
messageCreator
- callback to create a message- Throws:
JmsException
- checked JMSException converted to unchecked
-
send
Send a message to the specified destination. The MessageCreator callback creates the message given a Session.- Parameters:
destination
- the destination to send this message tomessageCreator
- callback to create a message- Throws:
JmsException
- checked JMSException converted to unchecked
-
send
Send a message to the specified destination. The MessageCreator callback creates the message given a Session.- 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
-
convertAndSend
Send the given object to the default destination, converting the object to a JMS message with a configured MessageConverter.This will only work with a default destination specified!
- Parameters:
message
- the object to convert to a message- Throws:
JmsException
- converted checked JMSException to unchecked
-
convertAndSend
Send the given object to the specified destination, converting the object to a JMS message with a configured MessageConverter.- Parameters:
destination
- the destination to send this message tomessage
- the object to convert to a message- Throws:
JmsException
- converted checked JMSException to unchecked
-
convertAndSend
Send the given object to the specified destination, converting the object to a JMS message with a configured MessageConverter.- 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
Send the given object to the default destination, converting the object to a JMS message with a configured MessageConverter. The MessagePostProcessor callback allows for modification of the message after conversion.This will only work with a default destination specified!
- Parameters:
message
- the object to convert to a messagepostProcessor
- the callback to modify the message- Throws:
JmsException
- checked JMSException converted to unchecked
-
convertAndSend
void convertAndSend(Destination destination, Object message, MessagePostProcessor postProcessor) throws JmsException Send the given object to the specified destination, converting the object to a JMS message with a configured MessageConverter. The MessagePostProcessor callback allows for modification of the message after conversion.- Parameters:
destination
- the destination to send this message tomessage
- the object to convert to a messagepostProcessor
- the callback to modify the message- Throws:
JmsException
- checked JMSException converted to unchecked
-
convertAndSend
void convertAndSend(String destinationName, Object message, MessagePostProcessor postProcessor) throws JmsException Send the given object to the specified destination, converting the object to a JMS message with a configured MessageConverter. The MessagePostProcessor callback allows for modification of the message after conversion.- Parameters:
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
Receive a message synchronously from the default destination, but only wait up to a specified time for delivery.This method should be used carefully, since it will block the thread until the message becomes available or until the timeout value is exceeded.
This will only work with a default destination specified!
- Returns:
- the message received by the consumer, or
null
if the timeout expires - Throws:
JmsException
- checked JMSException converted to unchecked
-
receive
Receive a message synchronously from the specified destination, but only wait up to a specified time for delivery.This method should be used carefully, since it will block the thread until the message becomes available or until the timeout value is exceeded.
- Parameters:
destination
- the destination to receive a message from- Returns:
- the message received by the consumer, or
null
if the timeout expires - Throws:
JmsException
- checked JMSException converted to unchecked
-
receive
Receive a message synchronously from the specified destination, but only wait up to a specified time for delivery.This method should be used carefully, since it will block the thread until the message becomes available or until the timeout value is exceeded.
- Parameters:
destinationName
- the name of the destination to send this message to (to be resolved to an actual destination by a DestinationResolver)- Returns:
- the message received by the consumer, or
null
if the timeout expires - Throws:
JmsException
- checked JMSException converted to unchecked
-
receiveSelected
Receive a message synchronously from the default destination, but only wait up to a specified time for delivery.This method should be used carefully, since it will block the thread until the message becomes available or until the timeout value is exceeded.
This will only work with a default destination specified!
- Parameters:
messageSelector
- the JMS message selector expression (ornull
if none). See the JMS specification for a detailed definition of selector expressions.- Returns:
- the message received by the consumer, or
null
if the timeout expires - Throws:
JmsException
- checked JMSException converted to unchecked
-
receiveSelected
@Nullable Message receiveSelected(Destination destination, String messageSelector) throws JmsException Receive a message synchronously from the specified destination, but only wait up to a specified time for delivery.This method should be used carefully, since it will block the thread until the message becomes available or until the timeout value is exceeded.
- Parameters:
destination
- the destination to receive a message frommessageSelector
- the JMS message selector expression (ornull
if none). See the JMS specification for a detailed definition of selector expressions.- Returns:
- the message received by the consumer, or
null
if the timeout expires - Throws:
JmsException
- checked JMSException converted to unchecked
-
receiveSelected
@Nullable Message receiveSelected(String destinationName, String messageSelector) throws JmsException Receive a message synchronously from the specified destination, but only wait up to a specified time for delivery.This method should be used carefully, since it will block the thread until the message becomes available or until the timeout value is exceeded.
- Parameters:
destinationName
- the name of the destination to send this message to (to be resolved to an actual destination by a DestinationResolver)messageSelector
- the JMS message selector expression (ornull
if none). See the JMS specification for a detailed definition of selector expressions.- Returns:
- the message received by the consumer, or
null
if the timeout expires - Throws:
JmsException
- checked JMSException converted to unchecked
-
receiveAndConvert
Receive a message synchronously from the default destination, but only wait up to a specified time for delivery. Convert the message into an object with a configured MessageConverter.This method should be used carefully, since it will block the thread until the message becomes available or until the timeout value is exceeded.
This will only work with a default destination specified!
- Returns:
- the message produced for the consumer, or
null
if the timeout expires - Throws:
JmsException
- checked JMSException converted to unchecked
-
receiveAndConvert
Receive a message synchronously from the specified destination, but only wait up to a specified time for delivery. Convert the message into an object with a configured MessageConverter.This method should be used carefully, since it will block the thread until the message becomes available or until the timeout value is exceeded.
- Parameters:
destination
- the destination to receive a message from- Returns:
- the message produced for the consumer, or
null
if the timeout expires - Throws:
JmsException
- checked JMSException converted to unchecked
-
receiveAndConvert
Receive a message synchronously from the specified destination, but only wait up to a specified time for delivery. Convert the message into an object with a configured MessageConverter.This method should be used carefully, since it will block the thread until the message becomes available or until the timeout value is exceeded.
- Parameters:
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
Receive a message synchronously from the default destination, but only wait up to a specified time for delivery. Convert the message into an object with a configured MessageConverter.This method should be used carefully, since it will block the thread until the message becomes available or until the timeout value is exceeded.
This will only work with a default destination specified!
- Parameters:
messageSelector
- the JMS message selector expression (ornull
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
@Nullable Object receiveSelectedAndConvert(Destination destination, String messageSelector) throws JmsException Receive a message synchronously from the specified destination, but only wait up to a specified time for delivery. Convert the message into an object with a configured MessageConverter.This method should be used carefully, since it will block the thread until the message becomes available or until the timeout value is exceeded.
- Parameters:
destination
- the destination to receive a message frommessageSelector
- the JMS message selector expression (ornull
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
@Nullable Object receiveSelectedAndConvert(String destinationName, String messageSelector) throws JmsException Receive a message synchronously from the specified destination, but only wait up to a specified time for delivery. Convert the message into an object with a configured MessageConverter.This method should be used carefully, since it will block the thread until the message becomes available or until the timeout value is exceeded.
- Parameters:
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 (ornull
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
-
sendAndReceive
Send a request message and receive the reply from a default destination. TheMessageCreator
callback creates the message given a Session. A temporary queue is created as part of this operation and is set in theJMSReplyTO
header of the message.This will only work with a default destination specified!
- Parameters:
messageCreator
- callback to create a request message- Returns:
- the reply, possibly
null
if the message could not be received, for example due to a timeout - Throws:
JmsException
- checked JMSException converted to unchecked- Since:
- 4.1
-
sendAndReceive
@Nullable Message sendAndReceive(Destination destination, MessageCreator messageCreator) throws JmsException Send a message and receive the reply from the specified destination. TheMessageCreator
callback creates the message given a Session. A temporary queue is created as part of this operation and is set in theJMSReplyTO
header of the message.- Parameters:
destination
- the destination to send this message tomessageCreator
- callback to create a message- Returns:
- the reply, possibly
null
if the message could not be received, for example due to a timeout - Throws:
JmsException
- checked JMSException converted to unchecked- Since:
- 4.1
-
sendAndReceive
@Nullable Message sendAndReceive(String destinationName, MessageCreator messageCreator) throws JmsException Send a message and receive the reply from the specified destination. TheMessageCreator
callback creates the message given a Session. A temporary queue is created as part of this operation and is set in theJMSReplyTO
header of the message.- 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
null
if the message could not be received, for example due to a timeout - Throws:
JmsException
- checked JMSException converted to unchecked- Since:
- 4.1
-
browse
Browse messages in the default JMS queue. The callback gives access to the JMS Session and QueueBrowser in order to browse the queue and react to the contents.- Parameters:
action
- callback object that exposes the session/browser pair- Returns:
- the result object from working with the session
- Throws:
JmsException
- checked JMSException converted to unchecked
-
browse
Browse messages in a JMS queue. The callback gives access to the JMS Session and QueueBrowser in order to browse the queue and react to the contents.- Parameters:
queue
- the queue to 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
Browse messages in a JMS queue. The callback gives access to the JMS Session and QueueBrowser in order to browse the queue and react to the contents.- Parameters:
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 <T> T browseSelected(String messageSelector, BrowserCallback<T> action) throws JmsException Browse selected messages in a JMS queue. The callback gives access to the JMS Session and QueueBrowser in order to browse the queue and react to the contents.- Parameters:
messageSelector
- the JMS message selector expression (ornull
if none). See the JMS specification for a detailed definition of selector expressions.action
- callback object that exposes the session/browser pair- Returns:
- the result object from working with the session
- Throws:
JmsException
- checked JMSException converted to unchecked
-
browseSelected
@Nullable <T> T browseSelected(Queue queue, String messageSelector, BrowserCallback<T> action) throws JmsException Browse selected messages in a JMS queue. The callback gives access to the JMS Session and QueueBrowser in order to browse the queue and react to the contents.- Parameters:
queue
- the queue to browsemessageSelector
- the JMS message selector expression (ornull
if none). See the JMS specification for a detailed definition of selector expressions.action
- callback object that exposes the session/browser pair- Returns:
- the result object from working with the session
- Throws:
JmsException
- checked JMSException converted to unchecked
-
browseSelected
@Nullable <T> T browseSelected(String queueName, String messageSelector, BrowserCallback<T> action) throws JmsException Browse selected messages in a JMS queue. The callback gives access to the JMS Session and QueueBrowser in order to browse the queue and react to the contents.- Parameters:
queueName
- the name of the queue to browse (to be resolved to an actual destination by a DestinationResolver)messageSelector
- the JMS message selector expression (ornull
if none). See the JMS specification for a detailed definition of selector expressions.action
- callback object that exposes the session/browser pair- Returns:
- the result object from working with the session
- Throws:
JmsException
- checked JMSException converted to unchecked
-