org.springframework.messaging.core

## Class AbstractMessagingTemplate<D>

- java.lang.Object
- - org.springframework.messaging.core.AbstractMessageSendingTemplate<D>
  - - org.springframework.messaging.core.AbstractMessagingTemplate<D>

- All Implemented Interfaces:
    MessageReceivingOperations<D>, MessageRequestReplyOperations<D>, MessageSendingOperations<D>
  Direct Known Subclasses:
    AbstractDestinationResolvingMessagingTemplate

      public abstract class AbstractMessagingTemplate<D>
      extends AbstractMessageSendingTemplate<D>
      implements MessageRequestReplyOperations<D>, MessageReceivingOperations<D>

  An extension of `AbstractMessageSendingTemplate` that adds support for receive as well as request-reply style operations as defined by `MessageReceivingOperations` and `MessageRequestReplyOperations`.
  Since:
    4.0
  Author:
    Mark Fisher, Rossen Stoyanchev

- - ### Field Summary

    - ### Fields inherited from class org.springframework.messaging.core.AbstractMessageSendingTemplate

      `logger`

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `AbstractMessagingTemplate()`

  - ### Method Summary

    All Methods Instance Methods Abstract Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `<T> T` | `convertSendAndReceive(D destination, Object request, Class<T> targetClass)` Convert the given request Object to serialized form, possibly using a `MessageConverter`, send it as a `Message` to the given destination, receive the reply and convert its body of the specified target class.
    `<T> T` | `convertSendAndReceive(D destination, Object request, Class<T> targetClass, MessagePostProcessor postProcessor)` Convert the given request Object to serialized form, possibly using a `MessageConverter`, apply the given post processor and send the resulting `Message` to the given destination, receive the reply and convert its body of the given target class.
    `<T> T` | `convertSendAndReceive(D destination, Object request, Map<String,Object> headers, Class<T> targetClass)` Convert the given request Object to serialized form, possibly using a `MessageConverter`, send it as a `Message` with the given headers, to the specified destination, receive the reply and convert its body of the specified target class.
    `<T> T` | `convertSendAndReceive(D destination, Object request, Map<String,Object> headers, Class<T> targetClass, MessagePostProcessor postProcessor)` Convert the given request Object to serialized form, possibly using a `MessageConverter`, wrap it as a message with the given headers, apply the given post processor and send the resulting `Message` to the specified destination, receive the reply and convert its body of the given target class.
    `<T> T` | `convertSendAndReceive(Object request, Class<T> targetClass)` Convert the given request Object to serialized form, possibly using a `MessageConverter`, send it as a `Message` to a default destination, receive the reply and convert its body of the specified target class.
    `<T> T` | `convertSendAndReceive(Object request, Class<T> targetClass, MessagePostProcessor postProcessor)` Convert the given request Object to serialized form, possibly using a `MessageConverter`, apply the given post processor and send the resulting `Message` to a default destination, receive the reply and convert its body of the given target class.
    `protected abstract Message<?>` | `doReceive(D destination)`
    `protected abstract Message<?>` | `doSendAndReceive(D destination, Message<?> requestMessage)`
    `Message<?>` | `receive()` Receive a message from a default destination.
    `Message<?>` | `receive(D destination)` Receive a message from the given destination.
    `<T> T` | `receiveAndConvert(Class<T> targetClass)` Receive a message from a default destination and convert its payload to the specified target class.
    `<T> T` | `receiveAndConvert(D destination, Class<T> targetClass)` Receive a message from the given destination and convert its payload to the specified target class.
    `Message<?>` | `sendAndReceive(D destination, Message<?> requestMessage)` Send a request message and receive the reply from the given destination.
    `Message<?>` | `sendAndReceive(Message<?> requestMessage)` Send a request message and receive the reply from a default destination.

    - ### Methods inherited from class org.springframework.messaging.core.AbstractMessageSendingTemplate

      `convertAndSend, convertAndSend, convertAndSend, convertAndSend, convertAndSend, convertAndSend, doSend, 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`

- - ### Constructor Detail

    - #### AbstractMessagingTemplate

          public AbstractMessagingTemplate()

  - ### Method Detail

    - #### receive

          public Message<?> receive()

      Description copied from interface: `MessageReceivingOperations`
      Receive a message from a default destination.
      Specified by:
        `receive` in interface `MessageReceivingOperations<D>`
      Returns:
        the received message, possibly `null` if the message could not be received, for example due to a timeout

    - #### receive

          public Message<?> receive(D destination)

      Description copied from interface: `MessageReceivingOperations`
      Receive a message from the given destination.
      Specified by:
        `receive` in interface `MessageReceivingOperations<D>`
      Parameters:
        `destination` - the target destination
      Returns:
        the received message, possibly `null` if the message could not be received, for example due to a timeout

    - #### doReceive

          protected abstract Message<?> doReceive(D destination)

    - #### receiveAndConvert

          public <T> T receiveAndConvert(Class<T> targetClass)

      Description copied from interface: `MessageReceivingOperations`
      Receive a message from a default destination and convert its payload to the specified target class.
      Specified by:
        `receiveAndConvert` in interface `MessageReceivingOperations<D>`
      Parameters:
        `targetClass` - the target class to convert the payload to
      Returns:
        the converted payload of the reply message, possibly `null` if the message could not be received, for example due to a timeout

    - #### receiveAndConvert

          public <T> T receiveAndConvert(D destination,
                                         Class<T> targetClass)

      Description copied from interface: `MessageReceivingOperations`
      Receive a message from the given destination and convert its payload to the specified target class.
      Specified by:
        `receiveAndConvert` in interface `MessageReceivingOperations<D>`
      Parameters:
        `destination` - the target destination
        `targetClass` - the target class to convert the payload to
      Returns:
        the converted payload of the reply message, possibly `null` if the message could not be received, for example due to a timeout

    - #### sendAndReceive

          public Message<?> sendAndReceive(Message<?> requestMessage)

      Description copied from interface: `MessageRequestReplyOperations`
      Send a request message and receive the reply from a default destination.
      Specified by:
        `sendAndReceive` in interface `MessageRequestReplyOperations<D>`
      Parameters:
        `requestMessage` - the message to send
      Returns:
        the reply, possibly `null` if the message could not be received, for example due to a timeout

    - #### sendAndReceive

          public Message<?> sendAndReceive(D destination,
                                           Message<?> requestMessage)

      Description copied from interface: `MessageRequestReplyOperations`
      Send a request message and receive the reply from the given destination.
      Specified by:
        `sendAndReceive` in interface `MessageRequestReplyOperations<D>`
      Parameters:
        `destination` - the target destination
        `requestMessage` - the message to send
      Returns:
        the reply, possibly `null` if the message could not be received, for example due to a timeout

    - #### doSendAndReceive

          protected abstract Message<?> doSendAndReceive(D destination,
                                                         Message<?> requestMessage)

    - #### convertSendAndReceive

          public <T> T convertSendAndReceive(Object request,
                                             Class<T> targetClass)

      Description copied from interface: `MessageRequestReplyOperations`
      Convert the given request Object to serialized form, possibly using a `MessageConverter`, send it as a `Message` to a default destination, receive the reply and convert its body of the specified target class.
      Specified by:
        `convertSendAndReceive` in interface `MessageRequestReplyOperations<D>`
      Parameters:
        `request` - payload for the request message to send
        `targetClass` - the target type to convert the payload of the reply to
      Returns:
        the payload of the reply message, possibly `null` if the message could not be received, for example due to a timeout

    - #### convertSendAndReceive

          public <T> T convertSendAndReceive(D destination,
                                             Object request,
                                             Class<T> targetClass)

      Description copied from interface: `MessageRequestReplyOperations`
      Convert the given request Object to serialized form, possibly using a `MessageConverter`, send it as a `Message` to the given destination, receive the reply and convert its body of the specified target class.
      Specified by:
        `convertSendAndReceive` in interface `MessageRequestReplyOperations<D>`
      Parameters:
        `destination` - the target destination
        `request` - payload for the request message to send
        `targetClass` - the target type to convert the payload of the reply to
      Returns:
        the payload of the reply message, possibly `null` if the message could not be received, for example due to a timeout

    - #### convertSendAndReceive

          public <T> T convertSendAndReceive(D destination,
                                             Object request,
                                             Map<String,Object> headers,
                                             Class<T> targetClass)

      Description copied from interface: `MessageRequestReplyOperations`
      Convert the given request Object to serialized form, possibly using a `MessageConverter`, send it as a `Message` with the given headers, to the specified destination, receive the reply and convert its body of the specified target class.
      Specified by:
        `convertSendAndReceive` in interface `MessageRequestReplyOperations<D>`
      Parameters:
        `destination` - the target destination
        `request` - payload for the request message to send
        `headers` - headers for the request message to send
        `targetClass` - the target type to convert the payload of the reply to
      Returns:
        the payload of the reply message, possibly `null` if the message could not be received, for example due to a timeout

    - #### convertSendAndReceive

          public <T> T convertSendAndReceive(Object request,
                                             Class<T> targetClass,
                                             MessagePostProcessor postProcessor)

      Description copied from interface: `MessageRequestReplyOperations`
      Convert the given request Object to serialized form, possibly using a `MessageConverter`, apply the given post processor and send the resulting `Message` to a default destination, receive the reply and convert its body of the given target class.
      Specified by:
        `convertSendAndReceive` in interface `MessageRequestReplyOperations<D>`
      Parameters:
        `request` - payload for the request message to send
        `targetClass` - the target type to convert the payload of the reply to
        `postProcessor` - post process to apply to the request message
      Returns:
        the payload of the reply message, possibly `null` if the message could not be received, for example due to a timeout

    - #### convertSendAndReceive

          public <T> T convertSendAndReceive(D destination,
                                             Object request,
                                             Class<T> targetClass,
                                             MessagePostProcessor postProcessor)

      Description copied from interface: `MessageRequestReplyOperations`
      Convert the given request Object to serialized form, possibly using a `MessageConverter`, apply the given post processor and send the resulting `Message` to the given destination, receive the reply and convert its body of the given target class.
      Specified by:
        `convertSendAndReceive` in interface `MessageRequestReplyOperations<D>`
      Parameters:
        `destination` - the target destination
        `request` - payload for the request message to send
        `targetClass` - the target type to convert the payload of the reply to
        `postProcessor` - post process to apply to the request message
      Returns:
        the payload of the reply message, possibly `null` if the message could not be received, for example due to a timeout

    - #### convertSendAndReceive

          public <T> T convertSendAndReceive(D destination,
                                             Object request,
                                             Map<String,Object> headers,
                                             Class<T> targetClass,
                                             MessagePostProcessor postProcessor)

      Description copied from interface: `MessageRequestReplyOperations`
      Convert the given request Object to serialized form, possibly using a `MessageConverter`, wrap it as a message with the given headers, apply the given post processor and send the resulting `Message` to the specified destination, receive the reply and convert its body of the given target class.
      Specified by:
        `convertSendAndReceive` in interface `MessageRequestReplyOperations<D>`
      Parameters:
        `destination` - the target destination
        `request` - payload for the request message to send
        `targetClass` - the target type to convert the payload of the reply to
        `postProcessor` - post process to apply to the request message
      Returns:
        the payload of the reply message, possibly `null` if the message could not be received, for example due to a timeout