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 ofJmsMessageOperations.- 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
Constructors Constructor Description JmsMessagingTemplate()Constructor 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
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidafterPropertiesSet()Invoked 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.voidconvertAndSend(String destinationName, Object payload, Map<String,Object> headers)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.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 MessagingExceptionconvertJmsException(JmsException ex)protected 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(String destinationName)protected Message<?>doReceive(Destination destination)Actually receive a message from the given destination.protected voiddoSend(String destinationName, Message<?> message)protected voiddoSend(Destination destination, Message<?> message)protected Message<?>doSendAndReceive(String destinationName, Message<?> requestMessage)protected Message<?>doSendAndReceive(Destination destination, Message<?> requestMessage)ConnectionFactorygetConnectionFactory()Return the ConnectionFactory that the underlyingJmsTemplateuses.StringgetDefaultDestinationName()Return the configured default destination name.MessageConvertergetJmsMessageConverter()JmsTemplategetJmsTemplate()Return the configuredJmsTemplate.protected StringgetRequiredDefaultDestinationName()Message<?>receive()Receive a message from a default destination.Message<?>receive(String destinationName)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(String destinationName, Message<?> message)Send a message to the given destination.voidsend(Message<?> message)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.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, 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, 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, send
Constructor Detail
JmsMessagingTemplate
public JmsMessagingTemplate()
Constructor for use with bean properties. RequiressetConnectionFactory(javax.jms.ConnectionFactory)orsetJmsTemplate(org.springframework.jms.core.JmsTemplate)to be called.
JmsMessagingTemplate
public JmsMessagingTemplate(ConnectionFactory connectionFactory)
Create aJmsMessagingTemplateinstance with the JMSConnectionFactoryto use, implicitly building aJmsTemplatebased on it.- Since:
- 4.1.2
JmsMessagingTemplate
public JmsMessagingTemplate(JmsTemplate jmsTemplate)
Create aJmsMessagingTemplateinstance with theJmsTemplateto use.
Method Detail
setConnectionFactory
public void setConnectionFactory(ConnectionFactory connectionFactory)
Set the ConnectionFactory to use for the underlyingJmsTemplate.- Since:
- 4.1.2
getConnectionFactory
public ConnectionFactory getConnectionFactory()
Return the ConnectionFactory that the underlyingJmsTemplateuses.- Since:
- 4.1.2
setJmsTemplate
public void setJmsTemplate(JmsTemplate jmsTemplate)
Set theJmsTemplateto use.
getJmsTemplate
public JmsTemplate getJmsTemplate()
Return the configuredJmsTemplate.
setJmsMessageConverter
public void setJmsMessageConverter(MessageConverter jmsMessageConverter)
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:
MessagingMessageConverter
getJmsMessageConverter
public MessageConverter getJmsMessageConverter()
setDefaultDestinationName
public void setDefaultDestinationName(String defaultDestinationName)
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
public String getDefaultDestinationName()
Return the configured default destination name.
afterPropertiesSet
public 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 interfaceInitializingBean
send
public void send(Message<?> message)
Description copied from interface:MessageSendingOperationsSend a message to a default destination.- Specified by:
sendin interfaceMessageSendingOperations<Destination>- Overrides:
sendin classAbstractMessageSendingTemplate<Destination>- Parameters:
message- the message to send
convertAndSend
public void convertAndSend(Object payload) throws MessagingException
Description 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 interfaceMessageSendingOperations<Destination>- Overrides:
convertAndSendin classAbstractMessageSendingTemplate<Destination>- Parameters:
payload- the Object to use as payload- Throws:
MessagingException
convertAndSend
public void convertAndSend(Object payload, 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 interfaceMessageSendingOperations<Destination>- Overrides:
convertAndSendin classAbstractMessageSendingTemplate<Destination>- Parameters:
payload- the Object to use as payloadpostProcessor- the post processor to apply to the message- Throws:
MessagingException
send
public void send(String destinationName, Message<?> message) throws 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:
MessagingException
convertAndSend
public void convertAndSend(String destinationName, Object payload) throws 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:
MessagingException
convertAndSend
public void convertAndSend(String destinationName, Object payload, Map<String,Object> headers) throws MessagingException
Description 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- headers for the message to send- Throws:
MessagingException
convertAndSend
public void convertAndSend(String destinationName, Object payload, 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 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, Map<String,Object> headers, MessagePostProcessor postProcessor) throws MessagingException
Description 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- headers for the message to sendpostProcessor- the post processor to apply to the message- Throws:
MessagingException
receive
public Message<?> receive()
Description copied from interface:MessageReceivingOperationsReceive a message from a default destination.- Specified by:
receivein interfaceMessageReceivingOperations<Destination>- Overrides:
receivein classAbstractMessageReceivingTemplate<Destination>- Returns:
- the received message, possibly
nullif the message could not be received, for example due to a timeout
receiveAndConvert
public <T> T receiveAndConvert(Class<T> targetClass)
Description copied from interface:MessageReceivingOperationsReceive a message from a default destination and convert its payload to the specified target class.- Specified by:
receiveAndConvertin interfaceMessageReceivingOperations<Destination>- Overrides:
receiveAndConvertin classAbstractMessageReceivingTemplate<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
receive
public Message<?> receive(String destinationName) throws 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:
MessagingException
receiveAndConvert
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 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:
MessagingException
sendAndReceive
public Message<?> sendAndReceive(Message<?> requestMessage)
Description copied from interface:MessageRequestReplyOperationsSend a request message and receive the reply from a default destination.- Specified by:
sendAndReceivein interfaceMessageRequestReplyOperations<Destination>- Overrides:
sendAndReceivein classAbstractMessagingTemplate<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
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 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:
MessagingException
convertSendAndReceive
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 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:
MessagingException
convertSendAndReceive
public <T> T convertSendAndReceive(Object request, Class<T> targetClass)
Description 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 interfaceMessageRequestReplyOperations<Destination>- Overrides:
convertSendAndReceivein 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
nullif the message could not be received, for example due to a timeout
convertSendAndReceive
public <T> T convertSendAndReceive(String destinationName, Object request, Map<String,Object> headers, Class<T> targetClass) throws MessagingException
Description 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- 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:
MessagingException
convertSendAndReceive
public <T> T convertSendAndReceive(Object request, Class<T> targetClass, 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 interfaceMessageRequestReplyOperations<Destination>- Overrides:
convertSendAndReceivein 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
nullif the message could not be received, for example due to a timeout
convertSendAndReceive
public <T> T convertSendAndReceive(String destinationName, Object request, Class<T> targetClass, 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 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:
MessagingException
convertSendAndReceive
public <T> T convertSendAndReceive(String destinationName, Object request, Map<String,Object> headers, Class<T> targetClass, 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
protected void doSend(Destination destination, Message<?> message)
- Specified by:
doSendin classAbstractMessageSendingTemplate<Destination>
doReceive
protected Message<?> doReceive(Destination destination)
Description copied from class:AbstractMessageReceivingTemplateActually receive a message from the given destination.- Specified by:
doReceivein classAbstractMessageReceivingTemplate<Destination>- Parameters:
destination- the target destination- Returns:
- the received message, possibly
nullif the message could not be received, for example due to a timeout
doSendAndReceive
protected Message<?> doSendAndReceive(Destination destination, Message<?> requestMessage)
- Specified by:
doSendAndReceivein classAbstractMessagingTemplate<Destination>
doSendAndReceive
protected Message<?> doSendAndReceive(String destinationName, Message<?> requestMessage)
getRequiredDefaultDestinationName
protected String getRequiredDefaultDestinationName()
convertJmsMessage
protected Message<?> convertJmsMessage(Message message)
convertJmsException
protected MessagingException convertJmsException(JmsException ex)