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:
org.springframework.beans.factory.InitializingBean,JmsMessageOperations,org.springframework.messaging.core.MessageReceivingOperations<Destination>,org.springframework.messaging.core.MessageRequestReplyOperations<Destination>,org.springframework.messaging.core.MessageSendingOperations<Destination>
public class JmsMessagingTemplate
extends org.springframework.messaging.core.AbstractMessagingTemplate<Destination>
implements JmsMessageOperations, org.springframework.beans.factory.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
ConstructorsConstructorDescriptionConstructor for use with bean properties.JmsMessagingTemplate(ConnectionFactory connectionFactory) Create aJmsMessagingTemplateinstance with the JMSConnectionFactoryto use, implicitly building aJmsTemplatebased on it.JmsMessagingTemplate(JmsTemplate jmsTemplate) Create aJmsMessagingTemplateinstance with theJmsTemplateto use. -
Method Summary
Modifier and TypeMethodDescriptionvoidvoidconvertAndSend(Object payload, org.springframework.messaging.core.MessagePostProcessor postProcessor) voidconvertAndSend(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.voidConvert 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.voidconvertAndSend(String destinationName, Object payload, Map<String, Object> headers, org.springframework.messaging.core.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.voidconvertAndSend(String destinationName, Object payload, org.springframework.messaging.core.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 org.springframework.messaging.MessagingExceptionprotected org.springframework.messaging.Message<?>convertJmsMessage(Message message) <T> TconvertSendAndReceive(Object request, Class<T> targetClass) <T> TconvertSendAndReceive(Object request, Class<T> targetClass, org.springframework.messaging.core.MessagePostProcessor postProcessor) <T> TconvertSendAndReceive(String destinationName, Object request, Class<T> targetClass) Convert the given request Object to serialized form, possibly using aMessageConverter, send it as aMessageto the given destination, receive the reply and convert its body of the specified target class.<T> TconvertSendAndReceive(String destinationName, Object request, Class<T> targetClass, org.springframework.messaging.core.MessagePostProcessor requestPostProcessor) Convert the given request Object to serialized form, possibly using aMessageConverter, apply the given post-processor and send the resultingMessageto the given destination, receive the reply and convert its body of the given target class.<T> TconvertSendAndReceive(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 aMessagewith the given headers, to the specified destination, receive the reply and convert its body of the specified target class.<T> TconvertSendAndReceive(String destinationName, Object request, Map<String, Object> headers, Class<T> targetClass, org.springframework.messaging.core.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 resultingMessageto the specified destination, receive the reply and convert its body of the given target class.protected org.springframework.messaging.Message<?>doReceive(Destination destination) protected org.springframework.messaging.Message<?>protected voiddoSend(Destination destination, org.springframework.messaging.Message<?> message) protected voidprotected org.springframework.messaging.Message<?>doSendAndReceive(Destination destination, org.springframework.messaging.Message<?> requestMessage) protected org.springframework.messaging.Message<?>doSendAndReceive(String destinationName, org.springframework.messaging.Message<?> requestMessage) Return the ConnectionFactory that the underlyingJmsTemplateuses.Return the configured default destination name.Return the configuredJmsTemplate.protected Stringorg.springframework.messaging.Message<?>receive()org.springframework.messaging.Message<?>Receive a message from the given destination.<T> TreceiveAndConvert(Class<T> targetClass) <T> TreceiveAndConvert(String destinationName, Class<T> targetClass) Receive a message from the given destination and convert its payload to the specified target class.voidSend a message to the given destination.voidsend(org.springframework.messaging.Message<?> message) org.springframework.messaging.Message<?>sendAndReceive(String destinationName, org.springframework.messaging.Message<?> requestMessage) Send a request message and receive the reply from the given destination.org.springframework.messaging.Message<?>sendAndReceive(org.springframework.messaging.Message<?> requestMessage) voidsetConnectionFactory(ConnectionFactory connectionFactory) Set the ConnectionFactory to use for the underlyingJmsTemplate.voidsetDefaultDestinationName(String defaultDestinationName) Configure the default destination name to use in send methods that don't have a destination argument.voidsetJmsMessageConverter(MessageConverter jmsMessageConverter) voidsetJmsTemplate(JmsTemplate jmsTemplate) Set theJmsTemplateto use.Methods inherited from class org.springframework.messaging.core.AbstractMessagingTemplate
convertSendAndReceive, convertSendAndReceive, convertSendAndReceive, convertSendAndReceive, sendAndReceiveMethods inherited from class org.springframework.messaging.core.AbstractMessageReceivingTemplate
doConvert, receive, receiveAndConvertMethods inherited from class org.springframework.messaging.core.AbstractMessageSendingTemplate
convertAndSend, convertAndSend, convertAndSend, convertAndSend, convertAndSend, doConvert, getDefaultDestination, getMessageConverter, getRequiredDefaultDestination, processHeadersToSend, send, setDefaultDestination, setMessageConverterMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.springframework.messaging.core.MessageReceivingOperations
receive, receiveAndConvertMethods inherited from interface org.springframework.messaging.core.MessageRequestReplyOperations
convertSendAndReceive, convertSendAndReceive, convertSendAndReceive, convertSendAndReceive, sendAndReceiveMethods 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 aJmsMessagingTemplateinstance with the JMSConnectionFactoryto use, implicitly building aJmsTemplatebased on it.- Since:
- 4.1.2
-
JmsMessagingTemplate
Create aJmsMessagingTemplateinstance with theJmsTemplateto use.
-
-
Method Details
-
setConnectionFactory
Set the ConnectionFactory to use for the underlyingJmsTemplate.- Since:
- 4.1.2
-
getConnectionFactory
Return the ConnectionFactory that the underlyingJmsTemplateuses.- Since:
- 4.1.2
-
setJmsTemplate
Set theJmsTemplateto use. -
getJmsTemplate
Return the configuredJmsTemplate. -
setJmsMessageConverter
Set theMessageConverterto use to convert aMessagefrom the messaging to and from aMessage. By default, aMessagingMessageConverteris defined using aSimpleMessageConverterto convert the payload of the message.Consider configuring a
MessagingMessageConverterwith a differentpayload converterfor 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.- See Also:
-
AbstractMessageSendingTemplate.setDefaultDestination(Object)
-
getDefaultDestinationName
Return the configured default destination name. -
afterPropertiesSet
public void afterPropertiesSet()- Specified by:
afterPropertiesSetin interfaceorg.springframework.beans.factory.InitializingBean
-
send
public void send(org.springframework.messaging.Message<?> message) - Specified by:
sendin interfaceorg.springframework.messaging.core.MessageSendingOperations<Destination>- Overrides:
sendin classorg.springframework.messaging.core.AbstractMessageSendingTemplate<Destination>
-
convertAndSend
public void convertAndSend(Object payload, @Nullable org.springframework.messaging.core.MessagePostProcessor postProcessor) throws org.springframework.messaging.MessagingException - Specified by:
convertAndSendin interfaceorg.springframework.messaging.core.MessageSendingOperations<Destination>- Overrides:
convertAndSendin classorg.springframework.messaging.core.AbstractMessageSendingTemplate<Destination>- Throws:
org.springframework.messaging.MessagingException
-
send
public void send(String destinationName, org.springframework.messaging.Message<?> message) throws org.springframework.messaging.MessagingException Description copied from interface:JmsMessageOperationsSend a message to the given destination.- Specified by:
sendin interfaceJmsMessageOperations- Parameters:
destinationName- the name of the target destinationmessage- the message to send- Throws:
org.springframework.messaging.MessagingException
-
convertAndSend
public void convertAndSend(String destinationName, Object payload) throws org.springframework.messaging.MessagingException Description copied from interface:JmsMessageOperationsConvert the given Object to serialized form, possibly using aMessageConverter, wrap it as a message and send it to the given destination.- Specified by:
convertAndSendin interfaceJmsMessageOperations- Parameters:
destinationName- the name of the target destinationpayload- the Object to use as payload- Throws:
org.springframework.messaging.MessagingException
-
convertAndSend
public void convertAndSend(String destinationName, Object payload, @Nullable Map<String, Object> headers) throws org.springframework.messaging.MessagingExceptionDescription copied from interface:JmsMessageOperationsConvert 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:
convertAndSendin interfaceJmsMessageOperations- Parameters:
destinationName- the name of the target destinationpayload- the Object to use as payloadheaders- the headers for the message to send- Throws:
org.springframework.messaging.MessagingException
-
convertAndSend
public void convertAndSend(String destinationName, Object payload, @Nullable org.springframework.messaging.core.MessagePostProcessor postProcessor) throws org.springframework.messaging.MessagingException Description copied from interface:JmsMessageOperationsConvert 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:
convertAndSendin interfaceJmsMessageOperations- Parameters:
destinationName- the name of the target destinationpayload- the Object to use as payloadpostProcessor- the post-processor to apply to the message- Throws:
org.springframework.messaging.MessagingException
-
convertAndSend
public void convertAndSend(String destinationName, Object payload, @Nullable Map<String, Object> headers, @Nullable org.springframework.messaging.core.MessagePostProcessor postProcessor) throws org.springframework.messaging.MessagingExceptionDescription copied from interface:JmsMessageOperationsConvert 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:
convertAndSendin 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:
org.springframework.messaging.MessagingException
-
receive
@Nullable public org.springframework.messaging.Message<?> receive()- Specified by:
receivein interfaceorg.springframework.messaging.core.MessageReceivingOperations<Destination>- Overrides:
receivein classorg.springframework.messaging.core.AbstractMessageReceivingTemplate<Destination>
-
receiveAndConvert
- Specified by:
receiveAndConvertin interfaceorg.springframework.messaging.core.MessageReceivingOperations<Destination>- Overrides:
receiveAndConvertin classorg.springframework.messaging.core.AbstractMessageReceivingTemplate<Destination>
-
receive
@Nullable public org.springframework.messaging.Message<?> receive(String destinationName) throws org.springframework.messaging.MessagingException Description copied from interface:JmsMessageOperationsReceive a message from the given destination.- Specified by:
receivein interfaceJmsMessageOperations- Parameters:
destinationName- the name of the target destination- Returns:
- the received message, possibly
nullif the message could not be received, for example due to a timeout - Throws:
org.springframework.messaging.MessagingException
-
receiveAndConvert
@Nullable public <T> T receiveAndConvert(String destinationName, Class<T> targetClass) throws org.springframework.messaging.MessagingException Description copied from interface:JmsMessageOperationsReceive a message from the given destination and convert its payload to the specified target class.- Specified by:
receiveAndConvertin 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
nullif the message could not be received, for example due to a timeout - Throws:
org.springframework.messaging.MessagingException
-
sendAndReceive
@Nullable public org.springframework.messaging.Message<?> sendAndReceive(org.springframework.messaging.Message<?> requestMessage) - Specified by:
sendAndReceivein interfaceorg.springframework.messaging.core.MessageRequestReplyOperations<Destination>- Overrides:
sendAndReceivein classorg.springframework.messaging.core.AbstractMessagingTemplate<Destination>
-
sendAndReceive
@Nullable public org.springframework.messaging.Message<?> sendAndReceive(String destinationName, org.springframework.messaging.Message<?> requestMessage) throws org.springframework.messaging.MessagingException Description copied from interface:JmsMessageOperationsSend a request message and receive the reply from the given destination.- Specified by:
sendAndReceivein interfaceJmsMessageOperations- Parameters:
destinationName- the name of the target destinationrequestMessage- the message to send- Returns:
- the reply, possibly
nullif the message could not be received, for example due to a timeout - Throws:
org.springframework.messaging.MessagingException
-
convertSendAndReceive
@Nullable public <T> T convertSendAndReceive(String destinationName, Object request, Class<T> targetClass) throws org.springframework.messaging.MessagingException Description copied from interface:JmsMessageOperationsConvert the given request Object to serialized form, possibly using aMessageConverter, send it as aMessageto the given destination, receive the reply and convert its body of the specified target class.- Specified by:
convertSendAndReceivein 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
nullif the message could not be received, for example due to a timeout - Throws:
org.springframework.messaging.MessagingException
-
convertSendAndReceive
- Specified by:
convertSendAndReceivein interfaceorg.springframework.messaging.core.MessageRequestReplyOperations<Destination>- Overrides:
convertSendAndReceivein classorg.springframework.messaging.core.AbstractMessagingTemplate<Destination>
-
convertSendAndReceive
@Nullable public <T> T convertSendAndReceive(String destinationName, Object request, @Nullable Map<String, Object> headers, Class<T> targetClass) throws org.springframework.messaging.MessagingExceptionDescription copied from interface:JmsMessageOperationsConvert the given request Object to serialized form, possibly using aMessageConverter, send it as aMessagewith the given headers, to the specified destination, receive the reply and convert its body of the specified target class.- Specified by:
convertSendAndReceivein 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
nullif the message could not be received, for example due to a timeout - Throws:
org.springframework.messaging.MessagingException
-
convertSendAndReceive
@Nullable public <T> T convertSendAndReceive(Object request, Class<T> targetClass, @Nullable org.springframework.messaging.core.MessagePostProcessor postProcessor) - Specified by:
convertSendAndReceivein interfaceorg.springframework.messaging.core.MessageRequestReplyOperations<Destination>- Overrides:
convertSendAndReceivein classorg.springframework.messaging.core.AbstractMessagingTemplate<Destination>
-
convertSendAndReceive
@Nullable public <T> T convertSendAndReceive(String destinationName, Object request, Class<T> targetClass, @Nullable org.springframework.messaging.core.MessagePostProcessor requestPostProcessor) throws org.springframework.messaging.MessagingException Description copied from interface:JmsMessageOperationsConvert the given request Object to serialized form, possibly using aMessageConverter, apply the given post-processor and send the resultingMessageto the given destination, receive the reply and convert its body of the given target class.- Specified by:
convertSendAndReceivein 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
nullif the message could not be received, for example due to a timeout - Throws:
org.springframework.messaging.MessagingException
-
convertSendAndReceive
@Nullable public <T> T convertSendAndReceive(String destinationName, Object request, @Nullable Map<String, Object> headers, Class<T> targetClass, @Nullable org.springframework.messaging.core.MessagePostProcessor postProcessor) Description copied from interface:JmsMessageOperationsConvert 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 resultingMessageto the specified destination, receive the reply and convert its body of the given target class.- Specified by:
convertSendAndReceivein 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
nullif the message could not be received, for example due to a timeout
-
doSend
- Specified by:
doSendin classorg.springframework.messaging.core.AbstractMessageSendingTemplate<Destination>
-
doSend
-
doReceive
- Specified by:
doReceivein classorg.springframework.messaging.core.AbstractMessageReceivingTemplate<Destination>
-
doReceive
-
doSendAndReceive
@Nullable protected org.springframework.messaging.Message<?> doSendAndReceive(Destination destination, org.springframework.messaging.Message<?> requestMessage) - Specified by:
doSendAndReceivein classorg.springframework.messaging.core.AbstractMessagingTemplate<Destination>
-
doSendAndReceive
@Nullable protected org.springframework.messaging.Message<?> doSendAndReceive(String destinationName, org.springframework.messaging.Message<?> requestMessage) -
getRequiredDefaultDestinationName
-
convertJmsMessage
@Nullable protected org.springframework.messaging.Message<?> convertJmsMessage(@Nullable Message message) -
convertJmsException
-