Class MessagingMessageListenerAdapter

java.lang.Object
org.springframework.amqp.rabbit.listener.adapter.AbstractAdaptableMessageListener
org.springframework.amqp.rabbit.listener.adapter.MessagingMessageListenerAdapter
All Implemented Interfaces:
org.springframework.amqp.core.MessageListener, ChannelAwareMessageListener
Direct Known Subclasses:
BatchMessagingMessageListenerAdapter

public class MessagingMessageListenerAdapter extends AbstractAdaptableMessageListener
A MessageListener adapter that invokes a configurable HandlerAdapter.

Wraps the incoming AMQP Message to Spring's Message abstraction, copying the standard headers using a configurable AmqpHeaderMapper.

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

Since:
1.4
  • Constructor Details

    • MessagingMessageListenerAdapter

      public MessagingMessageListenerAdapter()
    • MessagingMessageListenerAdapter

      public MessagingMessageListenerAdapter(Object bean, Method method)
    • MessagingMessageListenerAdapter

      public MessagingMessageListenerAdapter(Object bean, Method method, boolean returnExceptions, RabbitListenerErrorHandler errorHandler)
    • MessagingMessageListenerAdapter

      protected MessagingMessageListenerAdapter(Object bean, Method method, boolean returnExceptions, RabbitListenerErrorHandler errorHandler, boolean batch)
  • Method Details

    • setAcknowledgeOnError

      public void setAcknowledgeOnError(boolean acknowledgeOnError)
      Set to false to prevent the framework from automatically acknowledging messages when the error handler returns null in MANUAL ack mode. This allows the error handler to manage acknowledgment itself (e.g. by calling channel.basicReject()) without causing a duplicate ack error. Default is true (auto-acknowledge on null return from error handler).
      Parameters:
      acknowledgeOnError - false to skip the auto-ack on null return from error handler.
      Since:
      3.2.11
    • setHandlerAdapter

      public void setHandlerAdapter(HandlerAdapter handlerAdapter)
      Set the HandlerAdapter to use to invoke the method processing an incoming Message.
      Parameters:
      handlerAdapter - HandlerAdapter instance.
    • getHandlerAdapter

      protected HandlerAdapter getHandlerAdapter()
    • isAsyncReplies

      public boolean isAsyncReplies()
    • setHeaderMapper

      public void setHeaderMapper(org.springframework.amqp.support.AmqpHeaderMapper headerMapper)
      Set the AmqpHeaderMapper implementation to use to map the standard AMQP headers. By default, a SimpleAmqpHeaderMapper is used.
      Parameters:
      headerMapper - the AmqpHeaderMapper instance.
      See Also:
      • SimpleAmqpHeaderMapper
    • getMessagingMessageConverter

      protected final org.springframework.amqp.support.converter.MessagingMessageConverter getMessagingMessageConverter()
      Returns:
      the MessagingMessageConverter for this listener, being able to convert Message.
    • setMessageConverter

      public void setMessageConverter(org.springframework.amqp.support.converter.MessageConverter messageConverter)
      Description copied from class: AbstractAdaptableMessageListener
      Set the converter that will convert incoming Rabbit messages to listener method arguments, and objects returned from listener methods back to Rabbit messages.

      The default converter is a SimpleMessageConverter, which is able to handle "text" content-types.

      Overrides:
      setMessageConverter in class AbstractAdaptableMessageListener
      Parameters:
      messageConverter - The message converter.
    • onMessage

      public void onMessage(org.springframework.amqp.core.Message amqpMessage, com.rabbitmq.client.Channel channel) throws Exception
      Description copied from interface: ChannelAwareMessageListener
      Callback for processing a received Rabbit message.

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

      Parameters:
      amqpMessage - the received AMQP message (never null)
      channel - the underlying Rabbit Channel (never null unless called by the stream listener container).
      Throws:
      Exception - Any.
    • asyncFailure

      protected void asyncFailure(org.springframework.amqp.core.Message request, com.rabbitmq.client.Channel channel, Throwable t, Object source)
      Overrides:
      asyncFailure in class AbstractAdaptableMessageListener
    • invokeHandlerAndProcessResult

      protected void invokeHandlerAndProcessResult(@Nullable org.springframework.amqp.core.Message amqpMessage, com.rabbitmq.client.Channel channel, org.springframework.messaging.Message<?> message) throws Exception
      Throws:
      Exception
    • toMessagingMessage

      protected org.springframework.messaging.Message<?> toMessagingMessage(org.springframework.amqp.core.Message amqpMessage)
    • invokeHandler

      protected InvocationResult invokeHandler(@Nullable org.springframework.amqp.core.Message amqpMessage, com.rabbitmq.client.Channel channel, org.springframework.messaging.Message<?> message)
      Invoke the handler, wrapping any exception to a ListenerExecutionFailedException with a dedicated error message.
      Parameters:
      amqpMessage - the raw message.
      channel - the channel.
      message - the messaging message.
      Returns:
      the result of invoking the handler.
    • buildMessage

      protected org.springframework.amqp.core.Message buildMessage(com.rabbitmq.client.Channel channel, Object result, Type genericType)
      Build a Rabbit message to be sent as response based on the given result object.
      Overrides:
      buildMessage in class AbstractAdaptableMessageListener
      Parameters:
      channel - the Rabbit Channel to operate on
      result - the content of the message, as returned from the listener method
      genericType - the generic type of the result.
      Returns:
      the Rabbit Message (never null)
      See Also: