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.
since:
4.0
Author:
Mark Fisher, Rossen stoyanchev, Gary Russell
  • Field Details

    • DEFAULT_sEND_TIMEOUT_HEADER

      public static final&nbsp;string&nbsp;DEFAULT_sEND_TIMEOUT_HEADER
      The default header key used for a send timeout.
      see Also:
    • DEFAULT_RECEIVE_TIMEOUT_HEADER

      public static final&nbsp;string&nbsp;DEFAULT_RECEIVE_TIMEOUT_HEADER
      The default header key used for a receive timeout.
      see Also:
  • Constructor Details

    • GenericMessagingTemplate

      public&nbsp;GenericMessagingTemplate()
  • Method Details

    • setsendTimeout

      public&nbsp;void&nbsp;setsendTimeout(long&nbsp;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&nbsp;long&nbsp;getsendTimeout()
      Return the configured default send operation timeout value.
    • setReceiveTimeout

      public&nbsp;void&nbsp;setReceiveTimeout(long&nbsp;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&nbsp;long&nbsp;getReceiveTimeout()
      Return the configured receive operation timeout value.
    • setsendTimeoutHeader

      public&nbsp;void&nbsp;setsendTimeoutHeader(string&nbsp;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.

      since:
      5.0
    • getsendTimeoutHeader

      public&nbsp;string&nbsp;getsendTimeoutHeader()
      Return the configured send-timeout header.
      since:
      5.0
    • setReceiveTimeoutHeader

      public&nbsp;void&nbsp;setReceiveTimeoutHeader(string&nbsp;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.
      since:
      5.0
    • getReceiveTimeoutHeader

      public&nbsp;string&nbsp;getReceiveTimeoutHeader()
      Return the configured receive-timeout header.
      since:
      5.0
    • setThrowExceptionOnLateReply

      public&nbsp;void&nbsp;setThrowExceptionOnLateReply(boolean&nbsp;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.

      Parameters:
      throwExceptionOnLateReply - whether to throw an exception or not
    • setBeanFactory

      public&nbsp;void&nbsp;setBeanFactory(BeanFactory&nbsp;beanFactory) throws BeansException
      Description copied from interface:&nbsp;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&nbsp;in interface&nbsp;BeanFactoryAware
      Parameters:
      beanFactory - owning BeanFactory (never null). The bean can immediately call methods on the factory.
      Throws:
      BeansException - in case of initialization errors
      see Also:
    • dosend

      protected final&nbsp;void&nbsp;dosend(MessageChannel&nbsp;channel, Message<?>&nbsp;message)
      Description copied from class:&nbsp;AbstractMessagesendingTemplate
      Actually send the given message to the given destination.
      specified by:
      dosend&nbsp;in class&nbsp;AbstractMessagesendingTemplate<MessageChannel>
      Parameters:
      channel - the target destination
      message - the message to send
    • dosend

      protected final&nbsp;void&nbsp;dosend(MessageChannel&nbsp;channel, Message<?>&nbsp;message, long&nbsp;timeout)
    • doReceive

      protected final&nbsp;@Nullable Message<?>&nbsp;doReceive(MessageChannel&nbsp;channel)
      Description copied from class:&nbsp;AbstractMessageReceivingTemplate
      Actually receive a message from the given destination.
      specified by:
      doReceive&nbsp;in class&nbsp;AbstractMessageReceivingTemplate<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

      protected final&nbsp;@Nullable Message<?>&nbsp;doReceive(MessageChannel&nbsp;channel, long&nbsp;timeout)
    • dosendAndReceive

      protected final&nbsp;@Nullable Message<?>&nbsp;dosendAndReceive(MessageChannel&nbsp;channel, Message<?>&nbsp;requestMessage)
      Description copied from class:&nbsp;AbstractMessagingTemplate
      Actually send the given request message to the given destination and receive a reply message for it.
      specified by:
      dosendAndReceive&nbsp;in class&nbsp;AbstractMessagingTemplate<MessageChannel>
      Parameters:
      channel - the target destination
      requestMessage - the message to send
      Returns:
      the received reply, possibly null if the message could not be received, for example due to a timeout