org.springframework.jms.listener.adapter

## Class MessagingMessageListenerAdapter

- java.lang.Object
- - org.springframework.jms.listener.adapter.AbstractAdaptableMessageListener
  - - org.springframework.jms.listener.adapter.MessagingMessageListenerAdapter

- All Implemented Interfaces:
    MessageListener, SessionAwareMessageListener<Message>, SubscriptionNameProvider

      public class MessagingMessageListenerAdapter
      extends AbstractAdaptableMessageListener
      implements SubscriptionNameProvider

  A `MessageListener` adapter that invokes a configurable `InvocableHandlerMethod`.

  Wraps the incoming `Message` in Spring's `Message` abstraction, copying the JMS standard headers using a configurable `JmsHeaderMapper`.

  The original `Message` and the `Session` are provided as additional arguments so that these can be injected as method arguments if necessary.

  As of Spring Framework 5.3.26, `MessagingMessageListenerAdapter` implements `SubscriptionNameProvider` in order to provide a meaningful default subscription name. See `getSubscriptionName()` for details.

  Since:
    4.1
  Author:
    Stephane Nicoll, Sam Brannen
  See Also:
    `Message`, `JmsHeaderMapper`, `InvocableHandlerMethod`

- - ### Field Summary

    - ### Fields inherited from class org.springframework.jms.listener.adapter.AbstractAdaptableMessageListener

      `logger`

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `MessagingMessageListenerAdapter()`

  - ### Method Summary

    All Methods Instance Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `String` | `getSubscriptionName()` Generate a subscription name for this `MessageListener` adapter based on the following rules.
    `void` | `onMessage(Message jmsMessage, Session session)` Callback for processing a received JMS message.
    `protected Object` | `preProcessResponse(Object result)` Pre-process the given result before it is converted to a `Message`.
    `void` | `setHandlerMethod(InvocableHandlerMethod handlerMethod)` Set the `InvocableHandlerMethod` to use to invoke the method processing an incoming `Message`.
    `protected Message<?>` | `toMessagingMessage(Message jmsMessage)`

    - ### Methods inherited from class org.springframework.jms.listener.adapter.AbstractAdaptableMessageListener

      `buildMessage, extractMessage, getDestinationResolver, getMessageConverter, getMessagingMessageConverter, getResponseDestination, getResponseQosSettings, handleListenerException, handleResult, onMessage, postProcessProducer, postProcessResponse, resolveDefaultResponseDestination, sendResponse, setDefaultResponseDestination, setDefaultResponseQueueName, setDefaultResponseTopicName, setDestinationResolver, setHeaderMapper, setMessageConverter, setResponseQosSettings`

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Constructor Detail

    - #### MessagingMessageListenerAdapter

          public MessagingMessageListenerAdapter()

  - ### Method Detail

    - #### setHandlerMethod

          public void setHandlerMethod(InvocableHandlerMethod handlerMethod)

      Set the `InvocableHandlerMethod` to use to invoke the method processing an incoming `Message`.

    - #### onMessage

          public void onMessage(Message jmsMessage,
                                @Nullable
                                Session session)
                         throws JMSException

      Description copied from interface: `SessionAwareMessageListener`
      Callback for processing a received JMS message.

      Implementors are supposed to process the given Message, typically sending reply messages through the given Session.

      Specified by:
        `onMessage` in interface `SessionAwareMessageListener<Message>`
      Specified by:
        `onMessage` in class `AbstractAdaptableMessageListener`
      Parameters:
        `jmsMessage` - the received JMS message (never `null`)
        `session` - the underlying JMS Session (never `null`)
      Throws:
        `JMSException` - if thrown by JMS methods

    - #### toMessagingMessage

          protected Message<?> toMessagingMessage(Message jmsMessage)

    - #### preProcessResponse

          protected Object preProcessResponse(Object result)

      Description copied from class: `AbstractAdaptableMessageListener`
      Pre-process the given result before it is converted to a `Message`.
      Overrides:
        `preProcessResponse` in class `AbstractAdaptableMessageListener`
      Parameters:
        `result` - the result of the invocation
      Returns:
        the payload response to handle, either the `result` argument or any other object (for instance wrapping the result).

    - #### getSubscriptionName

          public String getSubscriptionName()

      Generate a subscription name for this `MessageListener` adapter based on the following rules.
      - If the `handlerMethod` has been set, the generated subscription name takes the form of `handlerMethod.getBeanType().getName() + "." + handlerMethod.getMethod().getName()`.
      - Otherwise, the generated subscription name is the result of invoking `getClass().getName()`, which aligns with the default behavior of `AbstractMessageListenerContainer`.
      Specified by:
        `getSubscriptionName` in interface `SubscriptionNameProvider`
      Since:
        5.3.26
      See Also:
        `SubscriptionNameProvider.getSubscriptionName()`