Class 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.
Mark Fisher, Rossen Stoyanchev, Gary Russell
  • Field Details


      public static final String DEFAULT_SEND_TIMEOUT_HEADER
      The default header key used for a send timeout.
      See Also:

      public static final String 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.
      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.
      receiveTimeout - the receive timeout in milliseconds
      See Also:
    • getReceiveTimeout

      public long getReceiveTimeout()
      Return the configured receive operation timeout value.
    • setSendTimeoutHeader

      public void setSendTimeoutHeader(String sendTimeoutHeader)
      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.

    • getSendTimeoutHeader

      public String getSendTimeoutHeader()
      Return the configured send-timeout header.
    • setReceiveTimeoutHeader

      public void setReceiveTimeoutHeader(String receiveTimeoutHeader)
      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.
    • getReceiveTimeoutHeader

      public String getReceiveTimeoutHeader()
      Return the configured receive-timeout header.
    • 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 to true a MessageDeliveryException is raised in addition to the log message.

      throwExceptionOnLateReply - whether to throw an exception or not
    • setBeanFactory

      public void setBeanFactory(BeanFactory beanFactory) throws BeansException
      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 interface BeanFactoryAware
      beanFactory - owning BeanFactory (never null). The bean can immediately call methods on the factory.
      BeansException - in case of initialization errors
      See Also:
    • doSend

      protected final void doSend(MessageChannel channel, Message<?> message)
      Specified by:
      doSend in class AbstractMessageSendingTemplate<MessageChannel>
    • doSend

      protected final void doSend(MessageChannel channel, Message<?> message, long timeout)
    • doReceive

      @Nullable protected final Message<?> doReceive(MessageChannel channel)
      Description copied from class: AbstractMessageReceivingTemplate
      Actually receive a message from the given destination.
      Specified by:
      doReceive in class AbstractMessageReceivingTemplate<MessageChannel>
      channel - the target destination
      the received message, possibly null if the message could not be received, for example due to a timeout
    • doReceive

      @Nullable protected final Message<?> doReceive(MessageChannel channel, long timeout)
    • doSendAndReceive

      @Nullable protected final Message<?> doSendAndReceive(MessageChannel channel, Message<?> requestMessage)
      Specified by:
      doSendAndReceive in class AbstractMessagingTemplate<MessageChannel>