public class JmsMessagingTemplate extends AbstractMessagingTemplate<Destination> implements JmsMessageOperations, InitializingBean
JmsMessageOperations
.Modifier and Type | Class and Description |
---|---|
private static class |
JmsMessagingTemplate.MessagingMessageCreator |
Modifier and Type | Field and Description |
---|---|
private java.lang.String |
defaultDestinationName |
private MessageConverter |
jmsMessageConverter |
private JmsTemplate |
jmsTemplate |
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. |
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(java.lang.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(java.lang.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(java.lang.String destinationName,
java.lang.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(java.lang.String destinationName,
java.lang.Object payload,
java.util.Map<java.lang.String,java.lang.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(java.lang.String destinationName,
java.lang.Object payload,
java.util.Map<java.lang.String,java.lang.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(java.lang.String destinationName,
java.lang.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(javax.jms.Message message) |
<T> T |
convertSendAndReceive(java.lang.Object request,
java.lang.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(java.lang.Object request,
java.lang.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(java.lang.String destinationName,
java.lang.Object request,
java.lang.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(java.lang.String destinationName,
java.lang.Object request,
java.lang.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(java.lang.String destinationName,
java.lang.Object request,
java.util.Map<java.lang.String,java.lang.Object> headers,
java.lang.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(java.lang.String destinationName,
java.lang.Object request,
java.util.Map<java.lang.String,java.lang.Object> headers,
java.lang.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. |
private JmsMessagingTemplate.MessagingMessageCreator |
createMessageCreator(Message<?> message) |
protected Message<?> |
doReceive(Destination destination)
Actually receive a message from the given destination.
|
protected void |
doSend(Destination destination,
Message<?> message) |
protected Message<?> |
doSendAndReceive(Destination destination,
Message<?> requestMessage) |
ConnectionFactory |
getConnectionFactory()
Return the ConnectionFactory that the underlying
JmsTemplate uses. |
java.lang.String |
getDefaultDestinationName()
Return the configured default destination name.
|
MessageConverter |
getJmsMessageConverter()
Return the
MessageConverter to use to convert a Message
from the messaging to and from a javax.jms.Message . |
JmsTemplate |
getJmsTemplate()
Return the configured
JmsTemplate . |
protected java.lang.String |
getRequiredDefaultDestinationName() |
Message<?> |
receive()
Receive a message from a default destination.
|
Message<?> |
receive(java.lang.String destinationName)
Receive a message from the given destination.
|
<T> T |
receiveAndConvert(java.lang.Class<T> targetClass)
Receive a message from a default destination and convert its payload to the
specified target class.
|
<T> T |
receiveAndConvert(java.lang.String destinationName,
java.lang.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(java.lang.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(java.lang.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(java.lang.String defaultDestinationName)
Configure the default destination name to use in send methods that don't have
a destination argument.
|
void |
setJmsMessageConverter(MessageConverter jmsMessageConverter)
Set the
MessageConverter to use to convert a Message from
the messaging to and from a javax.jms.Message . |
void |
setJmsTemplate(JmsTemplate jmsTemplate)
Set the
JmsTemplate to use. |
doConvert
doConvert, getDefaultDestination, getMessageConverter, getRequiredDefaultDestination, processHeadersToSend, setDefaultDestination, setMessageConverter
private JmsTemplate jmsTemplate
private MessageConverter jmsMessageConverter
private java.lang.String defaultDestinationName
public JmsMessagingTemplate()
setConnectionFactory(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 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 javax.jms.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()
MessageConverter
to use to convert a Message
from the messaging to and from a javax.jms.Message
.public void setDefaultDestinationName(java.lang.String defaultDestinationName)
public java.lang.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(java.lang.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(java.lang.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(java.lang.String destinationName, Message<?> message) throws MessagingException
MessageSendingOperations
send
in interface JmsMessageOperations
send
in interface MessageSendingOperations<Destination>
send
in class AbstractMessageSendingTemplate<Destination>
destinationName
- the target destinationmessage
- the message to sendMessagingException
public void convertAndSend(java.lang.String destinationName, java.lang.Object payload) throws MessagingException
MessageSendingOperations
MessageConverter
,
wrap it as a message and send it to the given destination.convertAndSend
in interface JmsMessageOperations
convertAndSend
in interface MessageSendingOperations<Destination>
convertAndSend
in class AbstractMessageSendingTemplate<Destination>
destinationName
- the target destinationpayload
- the Object to use as payloadMessagingException
public void convertAndSend(java.lang.String destinationName, java.lang.Object payload, java.util.Map<java.lang.String,java.lang.Object> headers) throws MessagingException
MessageSendingOperations
MessageConverter
,
wrap it as a message with the given headers and send it to
the given destination.convertAndSend
in interface JmsMessageOperations
convertAndSend
in interface MessageSendingOperations<Destination>
convertAndSend
in class AbstractMessageSendingTemplate<Destination>
destinationName
- the target destinationpayload
- the Object to use as payloadheaders
- headers for the message to sendMessagingException
public void convertAndSend(java.lang.String destinationName, java.lang.Object payload, MessagePostProcessor postProcessor) throws MessagingException
MessageSendingOperations
MessageConverter
,
wrap it as a message, apply the given post processor, and send
the resulting message to the given destination.convertAndSend
in interface JmsMessageOperations
convertAndSend
in interface MessageSendingOperations<Destination>
convertAndSend
in class AbstractMessageSendingTemplate<Destination>
destinationName
- the target destinationpayload
- the Object to use as payloadpostProcessor
- the post processor to apply to the messageMessagingException
public void convertAndSend(java.lang.String destinationName, java.lang.Object payload, java.util.Map<java.lang.String,java.lang.Object> headers, MessagePostProcessor postProcessor) throws MessagingException
MessageSendingOperations
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
convertAndSend
in interface MessageSendingOperations<Destination>
convertAndSend
in class AbstractMessageSendingTemplate<Destination>
destinationName
- 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(java.lang.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(java.lang.String destinationName) throws MessagingException
MessageReceivingOperations
receive
in interface JmsMessageOperations
receive
in interface MessageReceivingOperations<Destination>
receive
in class AbstractMessageReceivingTemplate<Destination>
destinationName
- the target destinationnull
if the message could not
be received, for example due to a timeoutMessagingException
public <T> T receiveAndConvert(java.lang.String destinationName, java.lang.Class<T> targetClass) throws MessagingException
MessageReceivingOperations
receiveAndConvert
in interface JmsMessageOperations
receiveAndConvert
in interface MessageReceivingOperations<Destination>
receiveAndConvert
in class AbstractMessageReceivingTemplate<Destination>
destinationName
- 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(java.lang.String destinationName, Message<?> requestMessage) throws MessagingException
MessageRequestReplyOperations
sendAndReceive
in interface JmsMessageOperations
sendAndReceive
in interface MessageRequestReplyOperations<Destination>
sendAndReceive
in class AbstractMessagingTemplate<Destination>
destinationName
- the target destinationrequestMessage
- the message to sendnull
if the message could not be received,
for example due to a timeoutMessagingException
public <T> T convertSendAndReceive(java.lang.String destinationName, java.lang.Object request, java.lang.Class<T> targetClass) throws MessagingException
MessageRequestReplyOperations
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
convertSendAndReceive
in interface MessageRequestReplyOperations<Destination>
convertSendAndReceive
in class AbstractMessagingTemplate<Destination>
destinationName
- 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(java.lang.Object request, java.lang.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(java.lang.String destinationName, java.lang.Object request, java.util.Map<java.lang.String,java.lang.Object> headers, java.lang.Class<T> targetClass) throws MessagingException
MessageRequestReplyOperations
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
convertSendAndReceive
in interface MessageRequestReplyOperations<Destination>
convertSendAndReceive
in class AbstractMessagingTemplate<Destination>
destinationName
- 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(java.lang.Object request, java.lang.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(java.lang.String destinationName, java.lang.Object request, java.lang.Class<T> targetClass, MessagePostProcessor requestPostProcessor) throws MessagingException
MessageRequestReplyOperations
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
convertSendAndReceive
in interface MessageRequestReplyOperations<Destination>
convertSendAndReceive
in class AbstractMessagingTemplate<Destination>
destinationName
- 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(java.lang.String destinationName, java.lang.Object request, java.util.Map<java.lang.String,java.lang.Object> headers, java.lang.Class<T> targetClass, MessagePostProcessor postProcessor)
MessageRequestReplyOperations
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
convertSendAndReceive
in interface MessageRequestReplyOperations<Destination>
convertSendAndReceive
in class AbstractMessagingTemplate<Destination>
destinationName
- 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>
private JmsMessagingTemplate.MessagingMessageCreator createMessageCreator(Message<?> message)
protected java.lang.String getRequiredDefaultDestinationName()
protected Message<?> convertJmsMessage(javax.jms.Message message)
protected MessagingException convertJmsException(JmsException ex)