public class MessagingTemplate extends java.lang.Object implements MessagingOperations, org.springframework.beans.factory.BeanFactoryAware, org.springframework.beans.factory.InitializingBean
MessageChannels. It supports one-way send and receive calls as well
as request/reply.| Modifier and Type | Field and Description |
|---|---|
protected org.apache.commons.logging.Log |
logger |
| Constructor and Description |
|---|
MessagingTemplate()
Create a MessagingTemplate with no default channel.
|
MessagingTemplate(MessageChannel defaultChannel)
Create a MessagingTemplate with the given default channel.
|
| Modifier and Type | Method and Description |
|---|---|
void |
afterPropertiesSet() |
<T> void |
convertAndSend(MessageChannel channel,
T object)
Send the given object to the specified channel, converting the object
to a message with a configured MessageConverter.
|
<T> void |
convertAndSend(MessageChannel channel,
T object,
MessagePostProcessor postProcessor)
Send the given object to the specified channel, converting the object
to a message with a configured MessageConverter.
|
<T> void |
convertAndSend(java.lang.String channelName,
T object)
Send the given object to the specified channel, converting the object
to a message with a configured MessageConverter.
|
<T> void |
convertAndSend(java.lang.String channelName,
T object,
MessagePostProcessor postProcessor)
Send the given object to the specified channel, converting the object
to a message with a configured MessageConverter.
|
<T> void |
convertAndSend(T object)
Send the given object to the default channel, converting the object
to a message with a configured MessageConverter.
|
<T> void |
convertAndSend(T object,
MessagePostProcessor postProcessor)
Send the given object to the default channel, converting the object
to a message with a configured MessageConverter.
|
java.lang.Object |
convertSendAndReceive(MessageChannel channel,
java.lang.Object request)
Send the given request object to the specified channel, converting the object
to a message with a configured MessageConverter.
|
java.lang.Object |
convertSendAndReceive(MessageChannel channel,
java.lang.Object request,
MessagePostProcessor requestPostProcessor)
Send the given request object to the specified channel, converting the object
to a message with a configured MessageConverter.
|
java.lang.Object |
convertSendAndReceive(java.lang.Object request)
Send the given request object to the default channel, converting the object
to a message with a configured MessageConverter.
|
java.lang.Object |
convertSendAndReceive(java.lang.Object request,
MessagePostProcessor requestPostProcessor)
Send the given request object to the default channel, converting the object
to a message with a configured MessageConverter.
|
java.lang.Object |
convertSendAndReceive(java.lang.String channelName,
java.lang.Object request)
Send the given request object to the specified channel, converting the object
to a message with a configured MessageConverter.
|
java.lang.Object |
convertSendAndReceive(java.lang.String channelName,
java.lang.Object request,
MessagePostProcessor requestPostProcessor)
Send the given request object to the specified channel, converting the object
to a message with a configured MessageConverter.
|
<P> Message<P> |
receive()
Receive a message synchronously from the default channel, but only
wait up to a specified time for delivery.
|
<P> Message<P> |
receive(PollableChannel channel)
Receive a message synchronously from the specified channel, but only
wait up to a specified time for delivery.
|
<P> Message<P> |
receive(java.lang.String channelName)
Receive a message synchronously from the specified channel, but only
wait up to a specified time for delivery.
|
java.lang.Object |
receiveAndConvert()
Receive a message synchronously from the default channel, but only
wait up to a specified time for delivery.
|
java.lang.Object |
receiveAndConvert(PollableChannel channel)
Receive a message synchronously from the specified channel, but only
wait up to a specified time for delivery.
|
java.lang.Object |
receiveAndConvert(java.lang.String channelName)
Receive a message synchronously from the specified channel, but only
wait up to a specified time for delivery.
|
protected MessageChannel |
resolveChannelName(java.lang.String channelName)
Resolve the given channel name into a
MessageChannel,
via this template's ChannelResolver if available. |
<P> void |
send(Message<P> message)
Send a message to the default channel.
|
<P> void |
send(MessageChannel channel,
Message<P> message)
Send a message to the specified channel.
|
<P> void |
send(java.lang.String channelName,
Message<P> message)
Send a message to the specified channel.
|
Message<?> |
sendAndReceive(Message<?> requestMessage)
Send a message to the default channel and receive a reply.
|
Message<?> |
sendAndReceive(MessageChannel channel,
Message<?> requestMessage)
Send a message to the specified channel and receive a reply.
|
Message<?> |
sendAndReceive(java.lang.String channelName,
Message<?> requestMessage)
Send a message to the specified channel and receive a reply.
|
void |
setBeanFactory(org.springframework.beans.factory.BeanFactory beanFactory) |
void |
setChannelResolver(ChannelResolver channelResolver)
Set the
ChannelResolver that is to be used to resolve
MessageChannel references for this template. |
void |
setDefaultChannel(MessageChannel defaultChannel)
Specify the default MessageChannel to use when invoking the send and/or
receive methods that do not expect a channel parameter.
|
void |
setMessageConverter(MessageConverter messageConverter)
Set the
MessageConverter that is to be used to convert
between Messages and objects for this template. |
void |
setReceiveTimeout(long receiveTimeout)
Specify the timeout value to use for receive operations.
|
void |
setSendTimeout(long sendTimeout)
Specify the timeout value to use for send operations.
|
void |
setThrowExceptionOnLateReply(boolean throwExceptionOnLateReply)
Specify whether or not an attempt to send on the reply channel throws an exception
if no receiving thread will actually receive the reply.
|
public MessagingTemplate()
setDefaultChannel(MessageChannel).public MessagingTemplate(MessageChannel defaultChannel)
public void setDefaultChannel(MessageChannel defaultChannel)
public void setChannelResolver(ChannelResolver channelResolver)
ChannelResolver that is to be used to resolve
MessageChannel references for this template.
When running within an application context, the default resolver is a
BeanFactoryChannelResolver.
public void setMessageConverter(MessageConverter messageConverter)
MessageConverter that is to be used to convert
between Messages and objects for this template.
The default is SimpleMessageConverter.
public void setSendTimeout(long sendTimeout)
sendTimeout - the send timeout in millisecondspublic void setReceiveTimeout(long receiveTimeout)
receiveTimeout - the receive timeout in millisecondspublic void setBeanFactory(org.springframework.beans.factory.BeanFactory beanFactory)
setBeanFactory in interface org.springframework.beans.factory.BeanFactoryAwarepublic void setThrowExceptionOnLateReply(boolean throwExceptionOnLateReply)
throwExceptionOnLateReply - TRUE or FALSE.public void afterPropertiesSet()
afterPropertiesSet in interface org.springframework.beans.factory.InitializingBeanpublic <P> void send(Message<P> message)
MessagingOperationsThis will only work with a default channel specified!
send in interface MessagingOperationsmessage - the message to sendpublic <P> void send(MessageChannel channel, Message<P> message)
MessagingOperationssend in interface MessagingOperationschannel - the channel to which the message will be sentmessage - the message to sendpublic <P> void send(java.lang.String channelName,
Message<P> message)
MessagingOperationssend in interface MessagingOperationschannelName - the name of the channel to which the message will be sent
(to be resolved to an actual channel by a ChannelResolver)message - the message to sendpublic <T> void convertAndSend(T object)
MessagingOperationsThis will only work with a default channel specified!
convertAndSend in interface MessagingOperationsobject - the object to convert to a messagepublic <T> void convertAndSend(MessageChannel channel, T object)
MessagingOperationsconvertAndSend in interface MessagingOperationschannel - the channel to send this message toobject - the object to convert to a messagepublic <T> void convertAndSend(java.lang.String channelName,
T object)
MessagingOperationsconvertAndSend in interface MessagingOperationschannelName - the name of the channel to send this message to
(to be resolved to an actual channel by a ChannelResolver)object - the object to convert to a messagepublic <T> void convertAndSend(T object,
MessagePostProcessor postProcessor)
MessagingOperationsThis will only work with a default channel specified!
convertAndSend in interface MessagingOperationsobject - the object to convert to a messagepostProcessor - the callback to modify the messagepublic <T> void convertAndSend(MessageChannel channel, T object, MessagePostProcessor postProcessor)
MessagingOperationsconvertAndSend in interface MessagingOperationschannel - the channel to which the message will be sentobject - the object to convert to a messagepostProcessor - the callback to modify the messagepublic <T> void convertAndSend(java.lang.String channelName,
T object,
MessagePostProcessor postProcessor)
MessagingOperationsconvertAndSend in interface MessagingOperationschannelName - the name of the channel to which the message will be sent
(to be resolved to an actual channel by a ChannelResolver)object - the object to convert to a messagepostProcessor - the callback to modify the messagepublic <P> Message<P> receive()
MessagingOperationsThis method should be used carefully, since it will block the thread until the message becomes available or until the timeout value is exceeded.
This will only work with a default channel specified!
receive in interface MessagingOperationsnull if the timeout expirespublic <P> Message<P> receive(PollableChannel channel)
MessagingOperationsThis method should be used carefully, since it will block the thread until the message becomes available or until the timeout value is exceeded.
receive in interface MessagingOperationschannel - the channel from which a message should be receivednull if the timeout expirespublic <P> Message<P> receive(java.lang.String channelName)
MessagingOperationsThis method should be used carefully, since it will block the thread until the message becomes available or until the timeout value is exceeded.
receive in interface MessagingOperationschannelName - the name of the channel from which a message should be received
(to be resolved to an actual channel by a ChannelResolver)null if the timeout expirespublic java.lang.Object receiveAndConvert()
throws MessagingException
MessagingOperationsThis method should be used carefully, since it will block the thread until the message becomes available or until the timeout value is exceeded.
This will only work with a default channel specified!
receiveAndConvert in interface MessagingOperationsnull if the timeout expires.MessagingException - if an error occurs during message receptionpublic java.lang.Object receiveAndConvert(PollableChannel channel) throws MessagingException
MessagingOperationsThis method should be used carefully, since it will block the thread until the message becomes available or until the timeout value is exceeded.
receiveAndConvert in interface MessagingOperationschannel - the channel from which a message should be receivednull if the timeout expires.MessagingException - if an error occurs during message receptionpublic java.lang.Object receiveAndConvert(java.lang.String channelName)
throws MessagingException
MessagingOperationsThis method should be used carefully, since it will block the thread until the message becomes available or until the timeout value is exceeded.
receiveAndConvert in interface MessagingOperationschannelName - the name of the channel from which a message should be received
(to be resolved to an actual channel by a ChannelResolver)null if the timeout expires.MessagingException - if an error occurs during message receptionpublic Message<?> sendAndReceive(Message<?> requestMessage)
MessagingOperationsThis will only work with a default channel specified!
sendAndReceive in interface MessagingOperationsrequestMessage - the message to sendpublic Message<?> sendAndReceive(MessageChannel channel, Message<?> requestMessage)
MessagingOperationssendAndReceive in interface MessagingOperationschannel - the channel to which the request Message will be sentrequestMessage - the message to sendpublic Message<?> sendAndReceive(java.lang.String channelName, Message<?> requestMessage)
MessagingOperationssendAndReceive in interface MessagingOperationschannelName - the name of the channel to which the request Message will be sent
(to be resolved to an actual channel by a ChannelResolver)requestMessage - the message to sendpublic java.lang.Object convertSendAndReceive(java.lang.Object request)
MessagingOperationsThis will only work with a default channel specified!
convertSendAndReceive in interface MessagingOperationsrequest - the object to convert to a request messagepublic java.lang.Object convertSendAndReceive(MessageChannel channel, java.lang.Object request)
MessagingOperationsconvertSendAndReceive in interface MessagingOperationschannel - the channel to which the request message will be sentrequest - the object to convert to a request messagepublic java.lang.Object convertSendAndReceive(java.lang.String channelName,
java.lang.Object request)
MessagingOperationsconvertSendAndReceive in interface MessagingOperationschannelName - the name of the channel to which the request message will be sent
(to be resolved to an actual channel by a ChannelResolver)request - the object to convert to a request messagepublic java.lang.Object convertSendAndReceive(java.lang.Object request,
MessagePostProcessor requestPostProcessor)
MessagingOperationsThis will only work with a default channel specified!
convertSendAndReceive in interface MessagingOperationsrequest - the object to convert to a request messagerequestPostProcessor - the callback to modify the request messagepublic java.lang.Object convertSendAndReceive(MessageChannel channel, java.lang.Object request, MessagePostProcessor requestPostProcessor)
MessagingOperationsconvertSendAndReceive in interface MessagingOperationschannel - the channel to which the request message will be sentrequest - the object to convert to a request messagerequestPostProcessor - the callback to modify the request messagepublic java.lang.Object convertSendAndReceive(java.lang.String channelName,
java.lang.Object request,
MessagePostProcessor requestPostProcessor)
MessagingOperationsconvertSendAndReceive in interface MessagingOperationschannelName - the name of the channel to which the request message will be sent
(to be resolved to an actual channel by a ChannelResolver)request - the object to convert to a request messagerequestPostProcessor - the callback to modify the request messageprotected MessageChannel resolveChannelName(java.lang.String channelName)
MessageChannel,
via this template's ChannelResolver if available.channelName - the name of the channelMessageChanneljava.lang.IllegalStateException - if this template does not have a ChannelResolverChannelResolutionException - if the channel name cannot be resolvedsetChannelResolver(org.springframework.integration.support.channel.ChannelResolver)