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 SummaryFields inherited from class org.springframework.messaging.core.AbstractMessageSendingTemplateCONVERSION_HINT_HEADER, logger
- 
Constructor SummaryConstructorsConstructorDescriptionConstructor 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 SummaryModifier and TypeMethodDescriptionvoidInvoked by the containingBeanFactoryafter it has set all bean properties and satisfiedBeanFactoryAware,ApplicationContextAwareetc.voidconvertAndSend(Object payload) Convert the given Object to serialized form, possibly using aMessageConverter, wrap it as a message and send it to a default destination.voidconvertAndSend(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.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, 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, 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 MessagingExceptionprotected Message<?>convertJmsMessage(Message message) <T> TconvertSendAndReceive(Object request, Class<T> targetClass) Convert the given request Object to serialized form, possibly using aMessageConverter, send it as aMessageto a default destination, receive the reply and convert its body of the specified target class.<T> TconvertSendAndReceive(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 resultingMessageto a default destination, receive the reply and convert its body of the given target class.<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, 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, 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 Message<?>doReceive(Destination destination) Actually receive a message from the given destination.protected Message<?>protected voiddoSend(Destination destination, Message<?> message) protected voidprotected Message<?>doSendAndReceive(Destination destination, Message<?> requestMessage) protected Message<?>doSendAndReceive(String destinationName, Message<?> requestMessage) Return the ConnectionFactory that the underlyingJmsTemplateuses.Return the configured default destination name.Return the configuredJmsTemplate.protected StringMessage<?>receive()Receive a message from a default destination.Message<?>Receive a message from the given destination.<T> TreceiveAndConvert(Class<T> targetClass) Receive a message from a default destination and convert its payload to the specified target class.<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 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.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.AbstractMessagingTemplateconvertSendAndReceive, convertSendAndReceive, convertSendAndReceive, convertSendAndReceive, sendAndReceiveMethods inherited from class org.springframework.messaging.core.AbstractMessageReceivingTemplatedoConvert, receive, receiveAndConvertMethods inherited from class org.springframework.messaging.core.AbstractMessageSendingTemplateconvertAndSend, convertAndSend, convertAndSend, convertAndSend, doConvert, getDefaultDestination, getMessageConverter, getRequiredDefaultDestination, processHeadersToSend, send, setDefaultDestination, setMessageConverterMethods inherited from class java.lang.Objectclone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.springframework.messaging.core.MessageReceivingOperationsreceive, receiveAndConvertMethods inherited from interface org.springframework.messaging.core.MessageRequestReplyOperationsconvertSendAndReceive, convertSendAndReceive, convertSendAndReceive, convertSendAndReceive, sendAndReceiveMethods inherited from interface org.springframework.messaging.core.MessageSendingOperationsconvertAndSend, convertAndSend, convertAndSend, convertAndSend, send
- 
Constructor Details- 
JmsMessagingTemplatepublic JmsMessagingTemplate()Constructor for use with bean properties. RequiressetConnectionFactory(jakarta.jms.ConnectionFactory)orsetJmsTemplate(org.springframework.jms.core.JmsTemplate)to be called.
- 
JmsMessagingTemplateCreate aJmsMessagingTemplateinstance with the JMSConnectionFactoryto use, implicitly building aJmsTemplatebased on it.- Since:
- 4.1.2
 
- 
JmsMessagingTemplateCreate aJmsMessagingTemplateinstance with theJmsTemplateto use.
 
- 
- 
Method Details- 
setConnectionFactorySet the ConnectionFactory to use for the underlyingJmsTemplate.- Since:
- 4.1.2
 
- 
getConnectionFactoryReturn the ConnectionFactory that the underlyingJmsTemplateuses.- Since:
- 4.1.2
 
- 
setJmsTemplateSet theJmsTemplateto use.
- 
getJmsTemplateReturn the configuredJmsTemplate.
- 
setJmsMessageConverterSet 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
- 
setDefaultDestinationNameConfigure 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.
- 
getDefaultDestinationNameReturn the configured default destination name.
- 
afterPropertiesSetpublic void afterPropertiesSet()Description copied from interface:InitializingBeanInvoked by the containingBeanFactoryafter it has set all bean properties and satisfiedBeanFactoryAware,ApplicationContextAwareetc.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:
- afterPropertiesSetin interface- InitializingBean
 
- 
sendDescription copied from interface:MessageSendingOperationsSend a message to a default destination.- Specified by:
- sendin interface- MessageSendingOperations<Destination>
- Overrides:
- sendin class- AbstractMessageSendingTemplate<Destination>
- Parameters:
- message- the message to send
 
- 
convertAndSendDescription copied from interface:MessageSendingOperationsConvert the given Object to serialized form, possibly using aMessageConverter, wrap it as a message and send it to a default destination.- Specified by:
- convertAndSendin interface- MessageSendingOperations<Destination>
- Overrides:
- convertAndSendin class- AbstractMessageSendingTemplate<Destination>
- Parameters:
- payload- the Object to use as payload
- Throws:
- MessagingException
 
- 
convertAndSendpublic void convertAndSend(Object payload, @Nullable MessagePostProcessor postProcessor) throws MessagingException Description copied from interface:MessageSendingOperationsConvert 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:
- convertAndSendin interface- MessageSendingOperations<Destination>
- Overrides:
- convertAndSendin class- AbstractMessageSendingTemplate<Destination>
- Parameters:
- payload- the Object to use as payload
- postProcessor- the post processor to apply to the message
- Throws:
- MessagingException
 
- 
sendDescription copied from interface:JmsMessageOperationsSend a message to the given destination.- Specified by:
- sendin interface- JmsMessageOperations
- Parameters:
- destinationName- the name of the target destination
- message- the message to send
- Throws:
- MessagingException
 
- 
convertAndSendDescription 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 interface- JmsMessageOperations
- Parameters:
- destinationName- the name of the target destination
- payload- the Object to use as payload
- Throws:
- MessagingException
 
- 
convertAndSendpublic void convertAndSend(String destinationName, Object payload, @Nullable Map<String, Object> headers) throws 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 interface- JmsMessageOperations
- Parameters:
- destinationName- the name of the target destination
- payload- the Object to use as payload
- headers- the headers for the message to send
- Throws:
- MessagingException
 
- 
convertAndSendpublic void convertAndSend(String destinationName, Object payload, @Nullable MessagePostProcessor postProcessor) throws 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 interface- JmsMessageOperations
- Parameters:
- destinationName- the name of the target destination
- payload- the Object to use as payload
- postProcessor- the post processor to apply to the message
- Throws:
- MessagingException
 
- 
convertAndSendpublic void convertAndSend(String destinationName, Object payload, @Nullable Map<String, Object> headers, @Nullable MessagePostProcessor postProcessor) throws 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 interface- JmsMessageOperations
- Parameters:
- destinationName- the name of the target destination
- payload- the Object to use as payload
- headers- the headers for the message to send
- postProcessor- the post processor to apply to the message
- Throws:
- MessagingException
 
- 
receiveDescription copied from interface:MessageReceivingOperationsReceive a message from a default destination.- Specified by:
- receivein interface- MessageReceivingOperations<Destination>
- Overrides:
- receivein class- AbstractMessageReceivingTemplate<Destination>
- Returns:
- the received message, possibly nullif the message could not be received, for example due to a timeout
 
- 
receiveAndConvertDescription copied from interface:MessageReceivingOperationsReceive a message from a default destination and convert its payload to the specified target class.- Specified by:
- receiveAndConvertin interface- MessageReceivingOperations<Destination>
- Overrides:
- receiveAndConvertin class- AbstractMessageReceivingTemplate<Destination>
- Parameters:
- targetClass- 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
 
- 
receiveDescription copied from interface:JmsMessageOperationsReceive a message from the given destination.- Specified by:
- receivein interface- JmsMessageOperations
- 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:
- MessagingException
 
- 
receiveAndConvert@Nullable public <T> T receiveAndConvert(String destinationName, Class<T> targetClass) throws MessagingException Description copied from interface:JmsMessageOperationsReceive a message from the given destination and convert its payload to the specified target class.- Specified by:
- receiveAndConvertin interface- JmsMessageOperations
- Parameters:
- destinationName- the name of the target destination
- targetClass- 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:
- MessagingException
 
- 
sendAndReceiveDescription copied from interface:MessageRequestReplyOperationsSend a request message and receive the reply from a default destination.- Specified by:
- sendAndReceivein interface- MessageRequestReplyOperations<Destination>
- Overrides:
- sendAndReceivein class- AbstractMessagingTemplate<Destination>
- Parameters:
- requestMessage- the message to send
- Returns:
- the reply, possibly nullif 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:JmsMessageOperationsSend a request message and receive the reply from the given destination.- Specified by:
- sendAndReceivein interface- JmsMessageOperations
- Parameters:
- destinationName- the name of the target destination
- requestMessage- the message to send
- Returns:
- the reply, possibly nullif 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: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 interface- JmsMessageOperations
- Parameters:
- destinationName- the name of the target destination
- request- payload for the request message to send
- targetClass- 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:
- MessagingException
 
- 
convertSendAndReceiveDescription copied from interface:MessageRequestReplyOperationsConvert the given request Object to serialized form, possibly using aMessageConverter, send it as aMessageto a default destination, receive the reply and convert its body of the specified target class.- Specified by:
- convertSendAndReceivein interface- MessageRequestReplyOperations<Destination>
- Overrides:
- convertSendAndReceivein class- AbstractMessagingTemplate<Destination>
- Parameters:
- request- payload for the request message to send
- targetClass- 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
 
- 
convertSendAndReceive@Nullable public <T> T convertSendAndReceive(String destinationName, Object request, @Nullable Map<String, Object> headers, Class<T> targetClass) throws 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 interface- JmsMessageOperations
- Parameters:
- destinationName- the name of the target destination
- request- payload for the request message to send
- headers- the headers for the request message to send
- targetClass- 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:
- MessagingException
 
- 
convertSendAndReceive@Nullable public <T> T convertSendAndReceive(Object request, Class<T> targetClass, @Nullable MessagePostProcessor postProcessor) Description copied from interface:MessageRequestReplyOperationsConvert the given request Object to serialized form, possibly using aMessageConverter, apply the given post processor and send the resultingMessageto a default destination, receive the reply and convert its body of the given target class.- Specified by:
- convertSendAndReceivein interface- MessageRequestReplyOperations<Destination>
- Overrides:
- convertSendAndReceivein class- AbstractMessagingTemplate<Destination>
- Parameters:
- request- payload for the request message to send
- targetClass- the target type to convert the payload of the reply to
- postProcessor- 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
 
- 
convertSendAndReceive@Nullable public <T> T convertSendAndReceive(String destinationName, Object request, Class<T> targetClass, @Nullable MessagePostProcessor requestPostProcessor) throws 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 interface- JmsMessageOperations
- Parameters:
- destinationName- the name of the target destination
- request- payload for the request message to send
- targetClass- the target type to convert the payload of the reply to
- requestPostProcessor- 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:
- 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: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 interface- JmsMessageOperations
- Parameters:
- destinationName- the name of the target destination
- request- payload for the request message to send
- targetClass- the target type to convert the payload of the reply to
- postProcessor- 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 class- AbstractMessageSendingTemplate<Destination>
 
- 
doSend
- 
doReceiveDescription copied from class:AbstractMessageReceivingTemplateActually receive a message from the given destination.- Specified by:
- doReceivein class- AbstractMessageReceivingTemplate<Destination>
- Parameters:
- destination- the target destination
- Returns:
- the received message, possibly nullif the message could not be received, for example due to a timeout
 
- 
doReceive
- 
doSendAndReceive- Specified by:
- doSendAndReceivein class- AbstractMessagingTemplate<Destination>
 
- 
doSendAndReceive
- 
getRequiredDefaultDestinationName
- 
convertJmsMessage
- 
convertJmsException
 
-