Class GenericMessagingTemplate
java.lang.Object
org.springframework.messaging.core.AbstractMessageSendingTemplate<D>
org.springframework.messaging.core.AbstractMessageReceivingTemplate<D>
org.springframework.messaging.core.AbstractMessagingTemplate<D>
org.springframework.messaging.core.AbstractDestinationResolvingMessagingTemplate<MessageChannel>
org.springframework.messaging.core.GenericMessagingTemplate
- All Implemented Interfaces:
Aware
,BeanFactoryAware
,DestinationResolvingMessageReceivingOperations<MessageChannel>
,DestinationResolvingMessageRequestReplyOperations<MessageChannel>
,DestinationResolvingMessageSendingOperations<MessageChannel>
,MessageReceivingOperations<MessageChannel>
,MessageRequestReplyOperations<MessageChannel>
,MessageSendingOperations<MessageChannel>
public class GenericMessagingTemplate
extends AbstractDestinationResolvingMessagingTemplate<MessageChannel>
implements BeanFactoryAware
A messaging template that resolves destinations names to
MessageChannel
's
to send and receive messages from.- Since:
- 4.0
- Author:
- Mark Fisher, Rossen Stoyanchev, Gary Russell
-
Field Summary
Modifier and TypeFieldDescriptionstatic final String
The default header key used for a receive timeout.static final String
The default header key used for a send timeout.Fields inherited from class org.springframework.messaging.core.AbstractMessageSendingTemplate
CONVERSION_HINT_HEADER, logger
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionprotected final Message<?>
doReceive
(MessageChannel channel) Actually receive a message from the given destination.protected final Message<?>
doReceive
(MessageChannel channel, long timeout) protected final void
doSend
(MessageChannel channel, Message<?> message) protected final void
doSend
(MessageChannel channel, Message<?> message, long timeout) protected final Message<?>
doSendAndReceive
(MessageChannel channel, Message<?> requestMessage) long
Return the configured receive operation timeout value.Return the configured receive-timeout header.long
Return the configured default send operation timeout value.Return the configured send-timeout header.void
setBeanFactory
(BeanFactory beanFactory) Callback that supplies the owning factory to a bean instance.void
setReceiveTimeout
(long receiveTimeout) Configure the default timeout value to use for receive operations.void
setReceiveTimeoutHeader
(String receiveTimeoutHeader) Set the name of the header used to determine the send timeout (if present).void
setSendTimeout
(long sendTimeout) Configure the default timeout value to use for send operations.void
setSendTimeoutHeader
(String sendTimeoutHeader) Set the name of the header used to determine the send timeout (if present).void
setThrowExceptionOnLateReply
(boolean throwExceptionOnLateReply) Whether the thread sending a reply should have an exception raised if the receiving thread isn't going to receive the reply either because it timed out, or because it already received a reply, or because it got an exception while sending the request message.Methods inherited from class org.springframework.messaging.core.AbstractDestinationResolvingMessagingTemplate
convertAndSend, convertAndSend, convertAndSend, convertAndSend, convertSendAndReceive, convertSendAndReceive, convertSendAndReceive, convertSendAndReceive, getDestinationResolver, receive, receiveAndConvert, resolveDestination, send, sendAndReceive, setDestinationResolver
Methods inherited from class org.springframework.messaging.core.AbstractMessagingTemplate
convertSendAndReceive, convertSendAndReceive, convertSendAndReceive, convertSendAndReceive, convertSendAndReceive, convertSendAndReceive, sendAndReceive, sendAndReceive
Methods inherited from class org.springframework.messaging.core.AbstractMessageReceivingTemplate
doConvert, receive, receive, receiveAndConvert, receiveAndConvert
Methods inherited from class org.springframework.messaging.core.AbstractMessageSendingTemplate
convertAndSend, convertAndSend, convertAndSend, convertAndSend, convertAndSend, convertAndSend, doConvert, getDefaultDestination, getMessageConverter, getRequiredDefaultDestination, processHeadersToSend, send, 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, receive, receiveAndConvert, receiveAndConvert
Methods inherited from interface org.springframework.messaging.core.MessageRequestReplyOperations
convertSendAndReceive, convertSendAndReceive, convertSendAndReceive, convertSendAndReceive, convertSendAndReceive, convertSendAndReceive, sendAndReceive, sendAndReceive
Methods inherited from interface org.springframework.messaging.core.MessageSendingOperations
convertAndSend, convertAndSend, convertAndSend, convertAndSend, convertAndSend, convertAndSend, send, send
-
Field Details
-
DEFAULT_SEND_TIMEOUT_HEADER
The default header key used for a send timeout.- See Also:
-
DEFAULT_RECEIVE_TIMEOUT_HEADER
The default header key used for a receive timeout.- See Also:
-
-
Constructor Details
-
GenericMessagingTemplate
public GenericMessagingTemplate()
-
-
Method Details
-
setSendTimeout
public void setSendTimeout(long sendTimeout) Configure the default timeout value to use for send operations. May be overridden for individual messages.- Parameters:
sendTimeout
- the send timeout in milliseconds- See Also:
-
getSendTimeout
public long getSendTimeout()Return the configured default send operation timeout value. -
setReceiveTimeout
public void setReceiveTimeout(long receiveTimeout) Configure the default timeout value to use for receive operations. May be overridden for individual messages when using sendAndReceive operations.- Parameters:
receiveTimeout
- the receive timeout in milliseconds- See Also:
-
getReceiveTimeout
public long getReceiveTimeout()Return the configured receive operation timeout value. -
setSendTimeoutHeader
Set the name of the header used to determine the send timeout (if present). Default "sendTimeout".The header is removed before sending the message to avoid propagation.
- Since:
- 5.0
-
getSendTimeoutHeader
Return the configured send-timeout header.- Since:
- 5.0
-
setReceiveTimeoutHeader
Set the name of the header used to determine the send timeout (if present). Default "receiveTimeout". The header is removed before sending the message to avoid propagation.- Since:
- 5.0
-
getReceiveTimeoutHeader
Return the configured receive-timeout header.- Since:
- 5.0
-
setThrowExceptionOnLateReply
public void setThrowExceptionOnLateReply(boolean throwExceptionOnLateReply) Whether the thread sending a reply should have an exception raised if the receiving thread isn't going to receive the reply either because it timed out, or because it already received a reply, or because it got an exception while sending the request message.The default value is
false
in which case only a WARN message is logged. If set totrue
aMessageDeliveryException
is raised in addition to the log message.- Parameters:
throwExceptionOnLateReply
- whether to throw an exception or not
-
setBeanFactory
Description copied from interface:BeanFactoryAware
Callback that supplies the owning factory to a bean instance.Invoked after the population of normal bean properties but before an initialization callback such as
InitializingBean.afterPropertiesSet()
or a custom init-method.- Specified by:
setBeanFactory
in interfaceBeanFactoryAware
- Parameters:
beanFactory
- owning BeanFactory (nevernull
). The bean can immediately call methods on the factory.- Throws:
BeansException
- in case of initialization errors- See Also:
-
doSend
- Specified by:
doSend
in classAbstractMessageSendingTemplate<MessageChannel>
-
doSend
-
doReceive
Description copied from class:AbstractMessageReceivingTemplate
Actually receive a message from the given destination.- Specified by:
doReceive
in classAbstractMessageReceivingTemplate<MessageChannel>
- Parameters:
channel
- the target destination- Returns:
- the received message, possibly
null
if the message could not be received, for example due to a timeout
-
doReceive
-
doSendAndReceive
@Nullable protected final Message<?> doSendAndReceive(MessageChannel channel, Message<?> requestMessage) - Specified by:
doSendAndReceive
in classAbstractMessagingTemplate<MessageChannel>
-