Package org.springframework.jms.core
Class JmsMessagingTemplate
java.lang.Object
org.springframework.messaging.core.AbstractMessageSendingTemplate<D>
org.springframework.messaging.core.AbstractMessageReceivingTemplate<D>
org.springframework.messaging.core.AbstractMessagingTemplate<Destination>
org.springframework.jms.core.JmsMessagingTemplate
- All Implemented Interfaces:
InitializingBean
,JmsMessageOperations
,MessageReceivingOperations<Destination>
,MessageRequestReplyOperations<Destination>
,MessageSendingOperations<Destination>
public class JmsMessagingTemplate
extends AbstractMessagingTemplate<Destination>
implements JmsMessageOperations, InitializingBean
An implementation of
JmsMessageOperations
.- Since:
- 4.1
- Author:
- Stephane Nicoll, Juergen Hoeller
-
Field Summary
Fields inherited from class org.springframework.messaging.core.AbstractMessageSendingTemplate
CONVERSION_HINT_HEADER, logger
-
Constructor Summary
ConstructorDescriptionConstructor for use with bean properties.JmsMessagingTemplate
(ConnectionFactory connectionFactory) Create aJmsMessagingTemplate
instance with the JMSConnectionFactory
to use, implicitly building aJmsTemplate
based on it.JmsMessagingTemplate
(JmsTemplate jmsTemplate) Create aJmsMessagingTemplate
instance with theJmsTemplate
to use. -
Method Summary
Modifier and TypeMethodDescriptionvoid
Invoked by the containingBeanFactory
after it has set all bean properties and satisfiedBeanFactoryAware
,ApplicationContextAware
etc.void
convertAndSend
(Object payload, MessagePostProcessor postProcessor) Convert the given Object to serialized form, possibly using aMessageConverter
, wrap it as a message, apply the given post processor, and send the resulting message to a default destination.void
convertAndSend
(String destinationName, Object payload) Convert the given Object to serialized form, possibly using aMessageConverter
, wrap it as a message and send it to the given destination.void
Convert the given Object to serialized form, possibly using aMessageConverter
, wrap it as a message with the given headers and send it to the given destination.void
convertAndSend
(String destinationName, Object payload, Map<String, Object> headers, MessagePostProcessor postProcessor) Convert the given Object to serialized form, possibly using aMessageConverter
, wrap it as a message with the given headers, apply the given post processor, and send the resulting message to the given destination.void
convertAndSend
(String destinationName, Object payload, MessagePostProcessor postProcessor) Convert the given Object to serialized form, possibly using aMessageConverter
, wrap it as a message, apply the given post processor, and send the resulting message to the given destination.protected MessagingException
protected Message<?>
convertJmsMessage
(Message message) <T> T
convertSendAndReceive
(Object request, Class<T> targetClass) Convert the given request Object to serialized form, possibly using aMessageConverter
, send it as aMessage
to a default destination, receive the reply and convert its body of the specified target class.<T> T
convertSendAndReceive
(Object request, Class<T> targetClass, MessagePostProcessor postProcessor) Convert the given request Object to serialized form, possibly using aMessageConverter
, apply the given post processor and send the resultingMessage
to a default destination, receive the reply and convert its body of the given target class.<T> T
convertSendAndReceive
(String destinationName, Object request, Class<T> targetClass) Convert the given request Object to serialized form, possibly using aMessageConverter
, send it as aMessage
to the given destination, receive the reply and convert its body of the specified target class.<T> T
convertSendAndReceive
(String destinationName, Object request, Class<T> targetClass, MessagePostProcessor requestPostProcessor) Convert the given request Object to serialized form, possibly using aMessageConverter
, apply the given post processor and send the resultingMessage
to the given destination, receive the reply and convert its body of the given target class.<T> T
convertSendAndReceive
(String destinationName, Object request, Map<String, Object> headers, Class<T> targetClass) Convert the given request Object to serialized form, possibly using aMessageConverter
, send it as aMessage
with the given headers, to the specified destination, receive the reply and convert its body of the specified target class.<T> T
convertSendAndReceive
(String destinationName, Object request, Map<String, Object> headers, Class<T> targetClass, MessagePostProcessor postProcessor) Convert the given request Object to serialized form, possibly using aMessageConverter
, wrap it as a message with the given headers, apply the given post processor and send the resultingMessage
to the specified destination, receive the reply and convert its body of the given target class.protected Message<?>
doReceive
(Destination destination) Actually receive a message from the given destination.protected Message<?>
protected void
doSend
(Destination destination, Message<?> message) protected void
protected Message<?>
doSendAndReceive
(Destination destination, Message<?> requestMessage) protected Message<?>
doSendAndReceive
(String destinationName, Message<?> requestMessage) Return the ConnectionFactory that the underlyingJmsTemplate
uses.Return the configured default destination name.Return the configuredJmsTemplate
.protected String
Message<?>
receive()
Receive a message from a default destination.Message<?>
Receive a message from the given destination.<T> T
receiveAndConvert
(Class<T> targetClass) Receive a message from a default destination and convert its payload to the specified target class.<T> T
receiveAndConvert
(String destinationName, Class<T> targetClass) Receive a message from the given destination and convert its payload to the specified target class.void
Send a message to the given destination.void
Send a message to a default destination.Message<?>
sendAndReceive
(String destinationName, Message<?> requestMessage) Send a request message and receive the reply from the given destination.Message<?>
sendAndReceive
(Message<?> requestMessage) Send a request message and receive the reply from a default destination.void
setConnectionFactory
(ConnectionFactory connectionFactory) Set the ConnectionFactory to use for the underlyingJmsTemplate
.void
setDefaultDestinationName
(String defaultDestinationName) Configure the default destination name to use in send methods that don't have a destination argument.void
setJmsMessageConverter
(MessageConverter jmsMessageConverter) void
setJmsTemplate
(JmsTemplate jmsTemplate) Set theJmsTemplate
to use.Methods inherited from class org.springframework.messaging.core.AbstractMessagingTemplate
convertSendAndReceive, convertSendAndReceive, convertSendAndReceive, convertSendAndReceive, sendAndReceive
Methods inherited from class org.springframework.messaging.core.AbstractMessageReceivingTemplate
doConvert, receive, receiveAndConvert
Methods inherited from class org.springframework.messaging.core.AbstractMessageSendingTemplate
convertAndSend, convertAndSend, convertAndSend, convertAndSend, convertAndSend, doConvert, getDefaultDestination, getMessageConverter, getRequiredDefaultDestination, processHeadersToSend, send, setDefaultDestination, setMessageConverter
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface org.springframework.messaging.core.MessageReceivingOperations
receive, receiveAndConvert
Methods inherited from interface org.springframework.messaging.core.MessageRequestReplyOperations
convertSendAndReceive, convertSendAndReceive, convertSendAndReceive, convertSendAndReceive, sendAndReceive
Methods inherited from interface org.springframework.messaging.core.MessageSendingOperations
convertAndSend, convertAndSend, convertAndSend, convertAndSend, convertAndSend, send
-
Constructor Details
-
JmsMessagingTemplate
public JmsMessagingTemplate()Constructor for use with bean properties. RequiressetConnectionFactory(jakarta.jms.ConnectionFactory)
orsetJmsTemplate(org.springframework.jms.core.JmsTemplate)
to be called. -
JmsMessagingTemplate
Create aJmsMessagingTemplate
instance with the JMSConnectionFactory
to use, implicitly building aJmsTemplate
based on it.- Since:
- 4.1.2
-
JmsMessagingTemplate
Create aJmsMessagingTemplate
instance with theJmsTemplate
to use.
-
-
Method Details
-
setConnectionFactory
Set the ConnectionFactory to use for the underlyingJmsTemplate
.- Since:
- 4.1.2
-
getConnectionFactory
Return the ConnectionFactory that the underlyingJmsTemplate
uses.- Since:
- 4.1.2
-
setJmsTemplate
Set theJmsTemplate
to use. -
getJmsTemplate
Return the configuredJmsTemplate
. -
setJmsMessageConverter
Set theMessageConverter
to use to convert aMessage
from the messaging to and from aMessage
. By default, aMessagingMessageConverter
is defined using aSimpleMessageConverter
to convert the payload of the message.Consider configuring a
MessagingMessageConverter
with a differentpayload converter
for more advanced scenarios.- See Also:
-
getJmsMessageConverter
-
setDefaultDestinationName
Configure the default destination name to use in send methods that don't have a destination argument. If a default destination is not configured, send methods without a destination argument will raise an exception if invoked. -
getDefaultDestinationName
Return the configured default destination name. -
afterPropertiesSet
public void afterPropertiesSet()Description copied from interface:InitializingBean
Invoked by the containingBeanFactory
after it has set all bean properties and satisfiedBeanFactoryAware
,ApplicationContextAware
etc.This method allows the bean instance to perform validation of its overall configuration and final initialization when all bean properties have been set.
- Specified by:
afterPropertiesSet
in interfaceInitializingBean
-
send
Description copied from interface:MessageSendingOperations
Send a message to a default destination.- Specified by:
send
in interfaceMessageSendingOperations<Destination>
- Overrides:
send
in classAbstractMessageSendingTemplate<Destination>
- Parameters:
message
- the message to send
-
convertAndSend
public void convertAndSend(Object payload, @Nullable MessagePostProcessor postProcessor) throws MessagingException Description copied from interface:MessageSendingOperations
Convert the given Object to serialized form, possibly using aMessageConverter
, wrap it as a message, apply the given post processor, and send the resulting message to a default destination.- Specified by:
convertAndSend
in interfaceMessageSendingOperations<Destination>
- Overrides:
convertAndSend
in classAbstractMessageSendingTemplate<Destination>
- Parameters:
payload
- the Object to use as payloadpostProcessor
- the post processor to apply to the message- Throws:
MessagingException
-
send
Description copied from interface:JmsMessageOperations
Send a message to the given destination.- Specified by:
send
in interfaceJmsMessageOperations
- Parameters:
destinationName
- the name of the target destinationmessage
- the message to send- Throws:
MessagingException
-
convertAndSend
Description copied from interface:JmsMessageOperations
Convert the given Object to serialized form, possibly using aMessageConverter
, wrap it as a message and send it to the given destination.- Specified by:
convertAndSend
in interfaceJmsMessageOperations
- Parameters:
destinationName
- the name of the target destinationpayload
- the Object to use as payload- Throws:
MessagingException
-
convertAndSend
public void convertAndSend(String destinationName, Object payload, @Nullable Map<String, Object> headers) throws MessagingExceptionDescription copied from interface:JmsMessageOperations
Convert the given Object to serialized form, possibly using aMessageConverter
, wrap it as a message with the given headers and send it to the given destination.- Specified by:
convertAndSend
in interfaceJmsMessageOperations
- Parameters:
destinationName
- the name of the target destinationpayload
- the Object to use as payloadheaders
- the headers for the message to send- Throws:
MessagingException
-
convertAndSend
public void convertAndSend(String destinationName, Object payload, @Nullable MessagePostProcessor postProcessor) throws MessagingException Description copied from interface:JmsMessageOperations
Convert the given Object to serialized form, possibly using aMessageConverter
, wrap it as a message, apply the given post processor, and send the resulting message to the given destination.- Specified by:
convertAndSend
in interfaceJmsMessageOperations
- Parameters:
destinationName
- the name of the target destinationpayload
- the Object to use as payloadpostProcessor
- the post processor to apply to the message- Throws:
MessagingException
-
convertAndSend
public void convertAndSend(String destinationName, Object payload, @Nullable Map<String, Object> headers, @Nullable MessagePostProcessor postProcessor) throws MessagingExceptionDescription copied from interface:JmsMessageOperations
Convert the given Object to serialized form, possibly using aMessageConverter
, wrap it as a message with the given headers, apply the given post processor, and send the resulting message to the given destination.- Specified by:
convertAndSend
in interfaceJmsMessageOperations
- Parameters:
destinationName
- the name of the target destinationpayload
- the Object to use as payloadheaders
- the headers for the message to sendpostProcessor
- the post processor to apply to the message- Throws:
MessagingException
-
receive
Description copied from interface:MessageReceivingOperations
Receive a message from a default destination.- Specified by:
receive
in interfaceMessageReceivingOperations<Destination>
- Overrides:
receive
in classAbstractMessageReceivingTemplate<Destination>
- Returns:
- the received message, possibly
null
if the message could not be received, for example due to a timeout
-
receiveAndConvert
Description copied from interface:MessageReceivingOperations
Receive a message from a default destination and convert its payload to the specified target class.- Specified by:
receiveAndConvert
in interfaceMessageReceivingOperations<Destination>
- Overrides:
receiveAndConvert
in classAbstractMessageReceivingTemplate<Destination>
- Parameters:
targetClass
- the target class to convert the payload to- Returns:
- the converted payload of the reply message, possibly
null
if the message could not be received, for example due to a timeout
-
receive
Description copied from interface:JmsMessageOperations
Receive a message from the given destination.- Specified by:
receive
in interfaceJmsMessageOperations
- Parameters:
destinationName
- the name of the target destination- Returns:
- the received message, possibly
null
if the message could not be received, for example due to a timeout - Throws:
MessagingException
-
receiveAndConvert
@Nullable public <T> T receiveAndConvert(String destinationName, Class<T> targetClass) throws MessagingException Description copied from interface:JmsMessageOperations
Receive a message from the given destination and convert its payload to the specified target class.- Specified by:
receiveAndConvert
in interfaceJmsMessageOperations
- Parameters:
destinationName
- the name of the target destinationtargetClass
- the target class to convert the payload to- Returns:
- the converted payload of the reply message, possibly
null
if the message could not be received, for example due to a timeout - Throws:
MessagingException
-
sendAndReceive
Description copied from interface:MessageRequestReplyOperations
Send a request message and receive the reply from a default destination.- Specified by:
sendAndReceive
in interfaceMessageRequestReplyOperations<Destination>
- Overrides:
sendAndReceive
in classAbstractMessagingTemplate<Destination>
- Parameters:
requestMessage
- the message to send- Returns:
- the reply, possibly
null
if the message could not be received, for example due to a timeout
-
sendAndReceive
@Nullable public Message<?> sendAndReceive(String destinationName, Message<?> requestMessage) throws MessagingException Description copied from interface:JmsMessageOperations
Send a request message and receive the reply from the given destination.- Specified by:
sendAndReceive
in interfaceJmsMessageOperations
- Parameters:
destinationName
- the name of the target destinationrequestMessage
- the message to send- Returns:
- the reply, possibly
null
if the message could not be received, for example due to a timeout - Throws:
MessagingException
-
convertSendAndReceive
@Nullable public <T> T convertSendAndReceive(String destinationName, Object request, Class<T> targetClass) throws MessagingException Description copied from interface:JmsMessageOperations
Convert the given request Object to serialized form, possibly using aMessageConverter
, send it as aMessage
to the given destination, receive the reply and convert its body of the specified target class.- Specified by:
convertSendAndReceive
in interfaceJmsMessageOperations
- Parameters:
destinationName
- the name of the target destinationrequest
- payload for the request message to sendtargetClass
- the target type to convert the payload of the reply to- Returns:
- the payload of the reply message, possibly
null
if the message could not be received, for example due to a timeout - Throws:
MessagingException
-
convertSendAndReceive
Description copied from interface:MessageRequestReplyOperations
Convert the given request Object to serialized form, possibly using aMessageConverter
, send it as aMessage
to a default destination, receive the reply and convert its body of the specified target class.- Specified by:
convertSendAndReceive
in interfaceMessageRequestReplyOperations<Destination>
- Overrides:
convertSendAndReceive
in classAbstractMessagingTemplate<Destination>
- Parameters:
request
- payload for the request message to sendtargetClass
- the target type to convert the payload of the reply to- Returns:
- the payload of the reply message, possibly
null
if the message could not be received, for example due to a timeout
-
convertSendAndReceive
@Nullable public <T> T convertSendAndReceive(String destinationName, Object request, @Nullable Map<String, Object> headers, Class<T> targetClass) throws MessagingExceptionDescription copied from interface:JmsMessageOperations
Convert the given request Object to serialized form, possibly using aMessageConverter
, send it as aMessage
with the given headers, to the specified destination, receive the reply and convert its body of the specified target class.- Specified by:
convertSendAndReceive
in interfaceJmsMessageOperations
- Parameters:
destinationName
- the name of the target destinationrequest
- payload for the request message to sendheaders
- the headers for the request message to sendtargetClass
- the target type to convert the payload of the reply to- Returns:
- the payload of the reply message, possibly
null
if the message could not be received, for example due to a timeout - Throws:
MessagingException
-
convertSendAndReceive
@Nullable public <T> T convertSendAndReceive(Object request, Class<T> targetClass, @Nullable MessagePostProcessor postProcessor) Description copied from interface:MessageRequestReplyOperations
Convert the given request Object to serialized form, possibly using aMessageConverter
, apply the given post processor and send the resultingMessage
to a default destination, receive the reply and convert its body of the given target class.- Specified by:
convertSendAndReceive
in interfaceMessageRequestReplyOperations<Destination>
- Overrides:
convertSendAndReceive
in classAbstractMessagingTemplate<Destination>
- Parameters:
request
- payload for the request message to sendtargetClass
- the target type to convert the payload of the reply topostProcessor
- post process to apply to the request message- Returns:
- the payload of the reply message, possibly
null
if the message could not be received, for example due to a timeout
-
convertSendAndReceive
@Nullable public <T> T convertSendAndReceive(String destinationName, Object request, Class<T> targetClass, @Nullable MessagePostProcessor requestPostProcessor) throws MessagingException Description copied from interface:JmsMessageOperations
Convert the given request Object to serialized form, possibly using aMessageConverter
, apply the given post processor and send the resultingMessage
to the given destination, receive the reply and convert its body of the given target class.- Specified by:
convertSendAndReceive
in interfaceJmsMessageOperations
- Parameters:
destinationName
- the name of the target destinationrequest
- payload for the request message to sendtargetClass
- the target type to convert the payload of the reply torequestPostProcessor
- post process to apply to the request message- Returns:
- the payload of the reply message, possibly
null
if the message could not be received, for example due to a timeout - Throws:
MessagingException
-
convertSendAndReceive
@Nullable public <T> T convertSendAndReceive(String destinationName, Object request, @Nullable Map<String, Object> headers, Class<T> targetClass, @Nullable MessagePostProcessor postProcessor) Description copied from interface:JmsMessageOperations
Convert the given request Object to serialized form, possibly using aMessageConverter
, wrap it as a message with the given headers, apply the given post processor and send the resultingMessage
to the specified destination, receive the reply and convert its body of the given target class.- Specified by:
convertSendAndReceive
in interfaceJmsMessageOperations
- Parameters:
destinationName
- the name of the target destinationrequest
- payload for the request message to sendtargetClass
- the target type to convert the payload of the reply topostProcessor
- post process to apply to the request message- Returns:
- the payload of the reply message, possibly
null
if the message could not be received, for example due to a timeout
-
doSend
- Specified by:
doSend
in classAbstractMessageSendingTemplate<Destination>
-
doSend
-
doReceive
Description copied from class:AbstractMessageReceivingTemplate
Actually receive a message from the given destination.- Specified by:
doReceive
in classAbstractMessageReceivingTemplate<Destination>
- Parameters:
destination
- the target destination- Returns:
- the received message, possibly
null
if the message could not be received, for example due to a timeout
-
doReceive
-
doSendAndReceive
- Specified by:
doSendAndReceive
in classAbstractMessagingTemplate<Destination>
-
doSendAndReceive
-
getRequiredDefaultDestinationName
-
convertJmsMessage
-
convertJmsException
-