Class AmqpMessagingListenerAdapter

java.lang.Object
org.springframework.amqp.client.listener.AmqpMessagingListenerAdapter
All Implemented Interfaces:
AcknowledgingProtonDeliveryListener, ProtonDeliveryListener, MessageListener

public class AmqpMessagingListenerAdapter extends Object implements AcknowledgingProtonDeliveryListener
The ProtonDeliveryListener implementation for POJO listeners delegating to the provided HandlerAdapter.

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

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

Since:
4.1
Author:
Artem Bilan
  • Constructor Details

    • AmqpMessagingListenerAdapter

      public AmqpMessagingListenerAdapter(HandlerAdapter handlerAdapter)
      Create an instance based on the provided HandlerAdapter.
      Parameters:
      handlerAdapter - the HandlerAdapter to invoke as POJO message listener.
  • Method Details

    • containerAckMode

      public void containerAckMode(AcknowledgeMode mode)
      Description copied from interface: MessageListener
      Called by the container to inform the listener of its acknowledgement mode.
      Specified by:
      containerAckMode in interface MessageListener
      Parameters:
      mode - the AcknowledgeMode.
    • isAsyncReplies

      public boolean isAsyncReplies()
      Description copied from interface: MessageListener
      Return true if this listener is request/reply and the replies are async.
      Specified by:
      isAsyncReplies in interface MessageListener
      Returns:
      true for async replies.
    • setDefaultRequeueRejected

      public void setDefaultRequeueRejected(boolean defaultRequeueRejected)
      Set the default behavior for messages rejection, for example, when the listener threw an exception. When true (default), messages will be requeued, otherwise - rejected. Setting to false causes all rejections to not be requeued. When set to true, the default can be overridden by the listener throwing an AmqpRejectAndDontRequeueException.
      Parameters:
      defaultRequeueRejected - false to reject messages by default.
    • setReplyPostProcessor

      public void setReplyPostProcessor(ReplyPostProcessor replyPostProcessor)
      Set a ReplyPostProcessor to post process a response message before it is sent. It is called after postProcessResponse(Message, Message) which sets up a correlationId property on the response message.
      Parameters:
      replyPostProcessor - the post-processor.
    • setErrorHandler

      public void setErrorHandler(AmqpListenerErrorHandler errorHandler)
      Set the AmqpListenerErrorHandler to invoke if the listener method throws an exception.
      Parameters:
      errorHandler - the error handler.
    • setReturnExceptions

      public void setReturnExceptions(boolean returnExceptions)
      Set whether exceptions thrown by the listener should be returned as a response message body to the sender using the normal replyTo/@SendTo semantics.
      Parameters:
      returnExceptions - true to return exceptions.
    • setReplyContentType

      public void setReplyContentType(String replyContentType)
      Set the reply content type. Overrides the one populated by a message converter.
      Parameters:
      replyContentType - the content type.
    • setResponseAddress

      public void setResponseAddress(String defaultReplyTo)
      Set the default replyTo address to use when sending response messages. This is only used if the replyTo from the received message is null.

      Response destinations are only relevant for listener methods that return result objects, which will be wrapped in a response message and sent to a response destination.

      It can be a string surrounded by "!{...}" in which case the expression is evaluated at runtime; see the reference manual for more information.

      Parameters:
      defaultReplyTo - The replyTo address.
    • setHeaderMapper

      public void setHeaderMapper(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:
    • setMessageConverter

      public void setMessageConverter(MessageConverter messageConverter)
      Set the converter to convert incoming messages to listener method arguments, and objects returned from listener methods for response messages. The default converter is a SimpleMessageConverter.
      Parameters:
      messageConverter - The message converter.
      See Also:
    • setBeanResolver

      public void setBeanResolver(BeanResolver beanResolver)
      Set a bean resolver for runtime SpEL expressions.
      Parameters:
      beanResolver - the resolver.
    • onDelivery

      public void onDelivery(org.apache.qpid.protonj2.client.Delivery delivery, @Nullable AmqpAcknowledgment acknowledgment) throws Exception
      Description copied from interface: AcknowledgingProtonDeliveryListener
      Process ProtonJ Delivery and optionally acknowledge it with a callback from the listener container. The implementation may choose to settle and replenish link credits some other way.
      Specified by:
      onDelivery in interface AcknowledgingProtonDeliveryListener
      Parameters:
      delivery - the delivery to handle.
      acknowledgment - the acknowledgment callback for this delivery.
      Throws:
      Exception - any exception from the handling logic.