public class JmsMessagingTemplate extends AbstractMessagingTemplate<Destination> implements JmsMessageOperations, InitializingBean
JmsMessageOperations
.CONVERSION_HINT_HEADER, logger
Constructor and Description |
---|
JmsMessagingTemplate()
Constructor for use with bean properties.
|
JmsMessagingTemplate(ConnectionFactory connectionFactory)
Create a
JmsMessagingTemplate instance with the JMS ConnectionFactory
to use, implicitly building a JmsTemplate based on it. |
JmsMessagingTemplate(JmsTemplate jmsTemplate)
Create a
JmsMessagingTemplate instance with the JmsTemplate to use. |
Modifier and Type | Method and Description |
---|---|
void |
afterPropertiesSet()
Invoked by a BeanFactory after it has set all bean properties supplied
(and satisfied BeanFactoryAware and ApplicationContextAware).
|
void |
convertAndSend(Object payload)
Convert the given Object to serialized form, possibly using a
MessageConverter ,
wrap it as a message and send it to a default destination. |
void |
convertAndSend(Object payload,
MessagePostProcessor postProcessor)
Convert the given Object to serialized form, possibly using a
MessageConverter ,
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 a
MessageConverter ,
wrap it as a message and send it to the given destination. |
void |
convertAndSend(String destinationName,
Object payload,
Map<String,Object> headers)
Convert the given Object to serialized form, possibly using a
MessageConverter ,
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 a
MessageConverter ,
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 a
MessageConverter ,
wrap it as a message, apply the given post processor, and send
the resulting message to the given destination. |
protected MessagingException |
convertJmsException(JmsException ex) |
protected Message<?> |
convertJmsMessage(Message message) |
<T> T |
convertSendAndReceive(Object request,
Class<T> targetClass)
Convert the given request Object to serialized form, possibly using a
MessageConverter , send
it as a Message 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 a
MessageConverter ,
apply the given post processor and send the resulting Message 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 a
MessageConverter , send
it as a Message 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 a
MessageConverter ,
apply the given post processor and send the resulting Message 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 a
MessageConverter , send
it as a Message 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 a
MessageConverter ,
wrap it as a message with the given headers, apply the given post processor
and send the resulting Message 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<?> |
doReceive(String destinationName) |
protected void |
doSend(Destination destination,
Message<?> message) |
protected void |
doSend(String destinationName,
Message<?> message) |
protected Message<?> |
doSendAndReceive(Destination destination,
Message<?> requestMessage) |
protected Message<?> |
doSendAndReceive(String destinationName,
Message<?> requestMessage) |
ConnectionFactory |
getConnectionFactory()
Return the ConnectionFactory that the underlying
JmsTemplate uses. |
String |
getDefaultDestinationName()
Return the configured default destination name.
|
MessageConverter |
getJmsMessageConverter()
|
JmsTemplate |
getJmsTemplate()
Return the configured
JmsTemplate . |
protected String |
getRequiredDefaultDestinationName() |
Message<?> |
receive()
Receive a message from a default destination.
|
Message<?> |
receive(String destinationName)
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(Message<?> message)
Send a message to a default destination.
|
void |
send(String destinationName,
Message<?> message)
Send a message to the given destination.
|
Message<?> |
sendAndReceive(Message<?> requestMessage)
Send a request message and receive the reply from a default destination.
|
Message<?> |
sendAndReceive(String destinationName,
Message<?> requestMessage)
Send a request message and receive the reply from the given destination.
|
void |
setConnectionFactory(ConnectionFactory connectionFactory)
Set the ConnectionFactory to use for the underlying
JmsTemplate . |
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 the
JmsTemplate to use. |
convertSendAndReceive, convertSendAndReceive, convertSendAndReceive, convertSendAndReceive, sendAndReceive
doConvert, receive, receiveAndConvert
convertAndSend, convertAndSend, convertAndSend, convertAndSend, doConvert, getDefaultDestination, getMessageConverter, getRequiredDefaultDestination, processHeadersToSend, send, setDefaultDestination, setMessageConverter
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
convertAndSend, convertAndSend, convertAndSend, convertAndSend, send
receive, receiveAndConvert
convertSendAndReceive, convertSendAndReceive, convertSendAndReceive, convertSendAndReceive, sendAndReceive
public JmsMessagingTemplate()
setConnectionFactory(javax.jms.ConnectionFactory)
or setJmsTemplate(org.springframework.jms.core.JmsTemplate)
to be called.public JmsMessagingTemplate(ConnectionFactory connectionFactory)
JmsMessagingTemplate
instance with the JMS ConnectionFactory
to use, implicitly building a JmsTemplate
based on it.public JmsMessagingTemplate(JmsTemplate jmsTemplate)
JmsMessagingTemplate
instance with the JmsTemplate
to use.public void setConnectionFactory(ConnectionFactory connectionFactory)
JmsTemplate
.public ConnectionFactory getConnectionFactory()
JmsTemplate
uses.public void setJmsTemplate(JmsTemplate jmsTemplate)
JmsTemplate
to use.public JmsTemplate getJmsTemplate()
JmsTemplate
.public void setJmsMessageConverter(MessageConverter jmsMessageConverter)
MessageConverter
to use to convert a Message
from
the messaging to and from a Message
. By default, a
MessagingMessageConverter
is defined using a SimpleMessageConverter
to convert the payload of the message.
Consider configuring a MessagingMessageConverter
with a different
payload converter
for more advanced scenarios.
MessagingMessageConverter
public MessageConverter getJmsMessageConverter()
public void setDefaultDestinationName(String defaultDestinationName)
public String getDefaultDestinationName()
public void afterPropertiesSet()
InitializingBean
This method allows the bean instance to perform initialization only possible when all bean properties have been set and to throw an exception in the event of misconfiguration.
afterPropertiesSet
in interface InitializingBean
public void send(Message<?> message)
MessageSendingOperations
send
in interface MessageSendingOperations<Destination>
send
in class AbstractMessageSendingTemplate<Destination>
message
- the message to sendpublic void convertAndSend(Object payload) throws MessagingException
MessageSendingOperations
MessageConverter
,
wrap it as a message and send it to a default destination.convertAndSend
in interface MessageSendingOperations<Destination>
convertAndSend
in class AbstractMessageSendingTemplate<Destination>
payload
- the Object to use as payloadMessagingException
public void convertAndSend(Object payload, MessagePostProcessor postProcessor) throws MessagingException
MessageSendingOperations
MessageConverter
,
wrap it as a message, apply the given post processor, and send
the resulting message to a default destination.convertAndSend
in interface MessageSendingOperations<Destination>
convertAndSend
in class AbstractMessageSendingTemplate<Destination>
payload
- the Object to use as payloadpostProcessor
- the post processor to apply to the messageMessagingException
public void send(String destinationName, Message<?> message) throws MessagingException
JmsMessageOperations
send
in interface JmsMessageOperations
destinationName
- the name of the target destinationmessage
- the message to sendMessagingException
public void convertAndSend(String destinationName, Object payload) throws MessagingException
JmsMessageOperations
MessageConverter
,
wrap it as a message and send it to the given destination.convertAndSend
in interface JmsMessageOperations
destinationName
- the name of the target destinationpayload
- the Object to use as payloadMessagingException
public void convertAndSend(String destinationName, Object payload, Map<String,Object> headers) throws MessagingException
JmsMessageOperations
MessageConverter
,
wrap it as a message with the given headers and send it to
the given destination.convertAndSend
in interface JmsMessageOperations
destinationName
- the name of the target destinationpayload
- the Object to use as payloadheaders
- headers for the message to sendMessagingException
public void convertAndSend(String destinationName, Object payload, MessagePostProcessor postProcessor) throws MessagingException
JmsMessageOperations
MessageConverter
,
wrap it as a message, apply the given post processor, and send
the resulting message to the given destination.convertAndSend
in interface JmsMessageOperations
destinationName
- the name of the target destinationpayload
- the Object to use as payloadpostProcessor
- the post processor to apply to the messageMessagingException
public void convertAndSend(String destinationName, Object payload, Map<String,Object> headers, MessagePostProcessor postProcessor) throws MessagingException
JmsMessageOperations
MessageConverter
,
wrap it as a message with the given headers, apply the given post processor,
and send the resulting message to the given destination.convertAndSend
in interface JmsMessageOperations
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 messageMessagingException
public Message<?> receive()
MessageReceivingOperations
receive
in interface MessageReceivingOperations<Destination>
receive
in class AbstractMessageReceivingTemplate<Destination>
null
if the message could not
be received, for example due to a timeoutpublic <T> T receiveAndConvert(Class<T> targetClass)
MessageReceivingOperations
receiveAndConvert
in interface MessageReceivingOperations<Destination>
receiveAndConvert
in class AbstractMessageReceivingTemplate<Destination>
targetClass
- the target class to convert the payload tonull
if
the message could not be received, for example due to a timeoutpublic Message<?> receive(String destinationName) throws MessagingException
JmsMessageOperations
receive
in interface JmsMessageOperations
destinationName
- the name of the target destinationnull
if the message could not
be received, for example due to a timeoutMessagingException
public <T> T receiveAndConvert(String destinationName, Class<T> targetClass) throws MessagingException
JmsMessageOperations
receiveAndConvert
in interface JmsMessageOperations
destinationName
- the name of the target destinationtargetClass
- the target class to convert the payload tonull
if
the message could not be received, for example due to a timeoutMessagingException
public Message<?> sendAndReceive(Message<?> requestMessage)
MessageRequestReplyOperations
sendAndReceive
in interface MessageRequestReplyOperations<Destination>
sendAndReceive
in class AbstractMessagingTemplate<Destination>
requestMessage
- the message to sendnull
if the message could not be received,
for example due to a timeoutpublic Message<?> sendAndReceive(String destinationName, Message<?> requestMessage) throws MessagingException
JmsMessageOperations
sendAndReceive
in interface JmsMessageOperations
destinationName
- the name of the target destinationrequestMessage
- the message to sendnull
if the message could not be received,
for example due to a timeoutMessagingException
public <T> T convertSendAndReceive(String destinationName, Object request, Class<T> targetClass) throws MessagingException
JmsMessageOperations
MessageConverter
, send
it as a Message
to the given destination, receive the reply and convert
its body of the specified target class.convertSendAndReceive
in interface JmsMessageOperations
destinationName
- the name of the target destinationrequest
- payload for the request message to sendtargetClass
- the target type to convert the payload of the reply tonull
if the message
could not be received, for example due to a timeoutMessagingException
public <T> T convertSendAndReceive(Object request, Class<T> targetClass)
MessageRequestReplyOperations
MessageConverter
, send
it as a Message
to a default destination, receive the reply and convert
its body of the specified target class.convertSendAndReceive
in interface MessageRequestReplyOperations<Destination>
convertSendAndReceive
in class AbstractMessagingTemplate<Destination>
request
- payload for the request message to sendtargetClass
- the target type to convert the payload of the reply tonull
if the message
could not be received, for example due to a timeoutpublic <T> T convertSendAndReceive(String destinationName, Object request, Map<String,Object> headers, Class<T> targetClass) throws MessagingException
JmsMessageOperations
MessageConverter
, send
it as a Message
with the given headers, to the specified destination,
receive the reply and convert its body of the specified target class.convertSendAndReceive
in interface JmsMessageOperations
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 tonull
if the message
could not be received, for example due to a timeoutMessagingException
public <T> T convertSendAndReceive(Object request, Class<T> targetClass, MessagePostProcessor postProcessor)
MessageRequestReplyOperations
MessageConverter
,
apply the given post processor and send the resulting Message
to a
default destination, receive the reply and convert its body of the given
target class.convertSendAndReceive
in interface MessageRequestReplyOperations<Destination>
convertSendAndReceive
in class AbstractMessagingTemplate<Destination>
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 messagenull
if the message
could not be received, for example due to a timeoutpublic <T> T convertSendAndReceive(String destinationName, Object request, Class<T> targetClass, MessagePostProcessor requestPostProcessor) throws MessagingException
JmsMessageOperations
MessageConverter
,
apply the given post processor and send the resulting Message
to the
given destination, receive the reply and convert its body of the given
target class.convertSendAndReceive
in interface JmsMessageOperations
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 messagenull
if the message
could not be received, for example due to a timeoutMessagingException
public <T> T convertSendAndReceive(String destinationName, Object request, Map<String,Object> headers, Class<T> targetClass, MessagePostProcessor postProcessor)
JmsMessageOperations
MessageConverter
,
wrap it as a message with the given headers, apply the given post processor
and send the resulting Message
to the specified destination, receive
the reply and convert its body of the given target class.convertSendAndReceive
in interface JmsMessageOperations
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 messagenull
if the message
could not be received, for example due to a timeoutprotected void doSend(Destination destination, Message<?> message)
doSend
in class AbstractMessageSendingTemplate<Destination>
protected Message<?> doReceive(Destination destination)
AbstractMessageReceivingTemplate
doReceive
in class AbstractMessageReceivingTemplate<Destination>
destination
- the target destinationnull
if the message could not
be received, for example due to a timeoutprotected Message<?> doSendAndReceive(Destination destination, Message<?> requestMessage)
doSendAndReceive
in class AbstractMessagingTemplate<Destination>
protected Message<?> doSendAndReceive(String destinationName, Message<?> requestMessage)
protected String getRequiredDefaultDestinationName()
protected MessagingException convertJmsException(JmsException ex)