Class GenericMessagingTemplate
java.lang.Object
org.springframework.messaging.core.AbstractMessageSendingTemplate<MessageChannel>
org.springframework.messaging.core.AbstractMessageReceivingTemplate<MessageChannel>
org.springframework.messaging.core.AbstractMessagingTemplate<MessageChannel>
org.springframework.messaging.core.AbstractDestinationResolvingMessagingTemplate<MessageChannel>
org.springframework.messaging.core.GenericMessagingTemplate
- All Implemented Interfaces:
org.springframework.beans.factory.Aware, org.springframework.beans.factory.BeanFactoryAware, DestinationResolvingMessageReceivingOperations<MessageChannel>, DestinationResolvingMessageRequestReplyOperations<MessageChannel>, DestinationResolvingMessageSendingOperations<MessageChannel>, MessageReceivingOperations<MessageChannel>, MessageRequestReplyOperations<MessageChannel>, MessageSendingOperations<MessageChannel>
public class GenericMessagingTemplate
extends AbstractDestinationResolvingMessagingTemplate<MessageChannel>
implements org.springframework.beans.factory.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
FieldsModifier and TypeFieldDescriptionstatic final StringThe default header key used for a receive timeout.static final StringThe default header key used for a send timeout.Fields inherited from class AbstractMessageSendingTemplate
CONVERSION_HINT_HEADER, logger -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptiondoReceive(MessageChannel channel) Actually receive a message from the given destination.doReceive(MessageChannel channel, long timeout) protected final voiddoSend(MessageChannel channel, Message<?> message) Actually send the given message to the given destination.protected final voiddoSend(MessageChannel channel, Message<?> message, long timeout) doSendAndReceive(MessageChannel channel, Message<?> requestMessage) Actually send the given request message to the given destination and receive a reply message for it.longReturn the configured receive operation timeout value.Return the configured receive-timeout header.longReturn the configured default send operation timeout value.Return the configured send-timeout header.voidsetBeanFactory(org.springframework.beans.factory.BeanFactory beanFactory) voidsetReceiveTimeout(long receiveTimeout) Configure the default timeout value to use for receive operations.voidsetReceiveTimeoutHeader(String receiveTimeoutHeader) Set the name of the header used to determine the send timeout (if present).voidsetSendTimeout(long sendTimeout) Configure the default timeout value to use for send operations.voidsetSendTimeoutHeader(String sendTimeoutHeader) Set the name of the header used to determine the send timeout (if present).voidsetThrowExceptionOnLateReply(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 AbstractDestinationResolvingMessagingTemplate
convertAndSend, convertAndSend, convertAndSend, convertAndSend, convertSendAndReceive, convertSendAndReceive, convertSendAndReceive, convertSendAndReceive, getDestinationResolver, receive, receiveAndConvert, resolveDestination, send, sendAndReceive, setDestinationResolverMethods inherited from class AbstractMessagingTemplate
convertSendAndReceive, convertSendAndReceive, convertSendAndReceive, convertSendAndReceive, convertSendAndReceive, convertSendAndReceive, convertSendAndReceive, convertSendAndReceive, sendAndReceive, sendAndReceiveMethods inherited from class AbstractMessageReceivingTemplate
doConvert, receive, receive, receiveAndConvert, receiveAndConvertMethods inherited from class AbstractMessageSendingTemplate
convertAndSend, convertAndSend, convertAndSend, convertAndSend, convertAndSend, convertAndSend, convertAndSend, convertAndSend, doConvert, getDefaultDestination, getMessageConverter, getRequiredDefaultDestination, processHeadersToSend, send, send, setDefaultDestination, setMessageConverterMethods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface MessageReceivingOperations
receive, receive, receiveAndConvert, receiveAndConvertMethods inherited from interface MessageRequestReplyOperations
convertSendAndReceive, convertSendAndReceive, convertSendAndReceive, convertSendAndReceive, convertSendAndReceive, convertSendAndReceive, convertSendAndReceive, convertSendAndReceive, sendAndReceive, sendAndReceiveMethods inherited from interface MessageSendingOperations
convertAndSend, convertAndSend, 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
-
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
-
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
falsein which case only a WARN message is logged. If set totrueaMessageDeliveryExceptionis raised in addition to the log message.- Parameters:
throwExceptionOnLateReply- whether to throw an exception or not
-
setBeanFactory
public void setBeanFactory(org.springframework.beans.factory.BeanFactory beanFactory) throws org.springframework.beans.BeansException - Specified by:
setBeanFactoryin interfaceorg.springframework.beans.factory.BeanFactoryAware- Throws:
org.springframework.beans.BeansException
-
doSend
Description copied from class:AbstractMessageSendingTemplateActually send the given message to the given destination.- Specified by:
doSendin classAbstractMessageSendingTemplate<MessageChannel>- Parameters:
channel- the target destinationmessage- the message to send
-
doSend
-
doReceive
Description copied from class:AbstractMessageReceivingTemplateActually receive a message from the given destination.- Specified by:
doReceivein classAbstractMessageReceivingTemplate<MessageChannel>- Parameters:
channel- the target destination- Returns:
- the received message, possibly
nullif the message could not be received, for example due to a timeout
-
doReceive
-
doSendAndReceive
protected final @Nullable Message<?> doSendAndReceive(MessageChannel channel, Message<?> requestMessage) Description copied from class:AbstractMessagingTemplateActually send the given request message to the given destination and receive a reply message for it.- Specified by:
doSendAndReceivein classAbstractMessagingTemplate<MessageChannel>- Parameters:
channel- the target destinationrequestMessage- the message to send- Returns:
- the received reply, possibly
nullif the message could not be received, for example due to a timeout
-