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
  • Field Details

    • messagingMessageConverter

      protected final org.springframework.amqp.support.converter.MessagingMessageConverterAdapter messagingMessageConverter
    • returnExceptions

      protected final boolean returnExceptions
    • errorHandler

      protected final @Nullable RabbitListenerErrorHandler errorHandler
  • Constructor Details

    • MessagingMessageListenerAdapter

      public MessagingMessageListenerAdapter()
    • MessagingMessageListenerAdapter

      public MessagingMessageListenerAdapter(@Nullable Object bean, @Nullable Method method)
    • MessagingMessageListenerAdapter

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

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

    • newMessagingMessageConverterAdapter

      protected org.springframework.amqp.support.converter.MessagingMessageConverterAdapter newMessagingMessageConverterAdapter(@Nullable Object bean, @Nullable Method method, boolean batch)
      Create a new MessagingMessageConverterAdapter instance based on the given bean and method. By default, additional provided argument type is a Channel. Extensions of this class can override this method to provide some other eligible additional argument types not required conversion.
      Parameters:
      bean - the bean of the method.
      method - the method to infer a payload type.
      batch - if the method is a batch listener.
      Returns:
      the MessagingMessageConverterAdapter instance.
    • 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(org.springframework.amqp.listener.adapter.HandlerAdapter handlerAdapter)
      Set the HandlerAdapter to use to invoke the method processing an incoming Message.
      Parameters:
      handlerAdapter - HandlerAdapter instance.
    • getHandlerAdapter

      protected org.springframework.amqp.listener.adapter.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(@Nullable 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, @Nullable 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, @Nullable com.rabbitmq.client.Channel channel, Throwable t, @Nullable Object source)
      Overrides:
      asyncFailure in class AbstractAdaptableMessageListener
    • handleException

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

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

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

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

      protected org.springframework.amqp.core.Message buildMessage(@Nullable com.rabbitmq.client.Channel channel, @Nullable Object result, @Nullable Type genericType)
      Build a Rabbit message to be sent as a 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: