Annotation Interface AmqpListener


@Target({METHOD,ANNOTATION_TYPE}) @Retention(RUNTIME) @MessageMapping @Documented @Repeatable(AmqpListeners.class) public @interface AmqpListener
Annotation that marks a method to be the target of an AMQP 1.0 message listener on the specified addresses(). The containerFactory() identifies the MethodAmqpMessageListenerContainerFactory to build an AMQP listener container. If not set, a default container factory is assumed to be available with a bean name AmqpDefaultConfiguration.DEFAULT_AMQP_LISTENER_CONTAINER_FACTORY_BEAN_NAME.

Processing of @AmqpListener annotations is performed by registering a AmqpListenerAnnotationBeanPostProcessor. This can be done manually or, more conveniently, through the EnableAmqp annotation.

Annotated methods are allowed to have flexible signatures similar to what MessageMapping provides, that is

  • Message
  • Message to use the messaging abstraction counterpart
  • Payload -annotated method arguments including the support of validation
  • Header -annotated method arguments to extract a specific header value, including standard AMQP headers defined by AmqpHeaders
  • Headers -annotated argument that must also be assignable to Map for getting access to all headers.
  • MessageHeaders arguments for getting access to all headers.
  • MessageHeaderAccessor or AmqpMessageHeaderAccessor for convenient access to all method arguments.
  • AmqpAcknowledgment - a convenient abstraction for manual acks.
  • Delivery - native ProtonJ delivery container for low-level API.

Annotated methods may have a non void return type. When they do, the result of the method invocation is sent as a reply to the queue defined by the ReplyTo header of the incoming message. When this value is not set, a default queue can be provided by adding @SendTo to the method declaration.

Since:
4.1
See Also:
  • Element Details

    • id

      String id
      The unique identifier of the container managing for this endpoint.

      If none is specified, an auto-generated one is provided.

      Returns:
      the id for the container managing for this endpoint.
      Default:
      ""
    • containerFactory

      String containerFactory
      The bean name of the MethodAmqpMessageListenerContainerFactory to use to create the message listener container responsible to serve this endpoint.

      If not specified, the default container factory is used, if any. If a SpEL expression is provided (#{...}), the expression can either evaluate to a container factory instance or a bean name.

      Returns:
      the MethodAmqpMessageListenerContainerFactory bean name.
      Default:
      ""
    • addresses

      String[] addresses
      The AMQP 1.0 addresses to listen to. The entries can be 'queue name', 'property-placeholder keys' or 'expressions'. Each expression must be resolved to the address. The addresses must exist.
      Returns:
      the addresses or expressions (SpEL) for the target listener container to listen from.
      See Also:
      • MessageListenerContainer
      Default:
      {}
    • initialCredits

      String initialCredits
      The initial number of credits to grant to the AMQP receiver. Can be SpEL expression or properties placeholder-based. Evaluates to int.
      Returns:
      the initial number of credits to grant to the AMQP receiver.
      Default:
      ""
    • returnExceptions

      String returnExceptions
      true to cause exceptions thrown by the listener to be sent to the sender using normal replyTo/@SendTo semantics. When false, the exception is thrown to the listener container and retry/DLQ processing could be performed on the AMQP broker side. Overrides the default set by the listener container factory.
      Returns:
      true to return exceptions. If the client side uses a RemoteInvocationAwareMessageConverterAdapter the exception will be re-thrown. Otherwise, the sender will receive a RemoteInvocationResult wrapping the exception.
      Default:
      ""
    • defaultRequeueRejected

      String defaultRequeueRejected
      Set the default behavior for messages rejection. Overrides the default set by the listener container factory. Can be SpEL or properties placeholder-based; evaluates to boolean.
      Returns:
      the default flag for messages rejection.
      Default:
      ""
    • errorHandler

      String errorHandler
      Set an AmqpListenerErrorHandler to invoke if the listener method throws an exception. Overrides the default set by the listener container factory. A simple String representing the bean name. If a SpEL expression (#{...}) is provided, the expression must evaluate to a bean name or a AmqpListenerErrorHandler instance.
      Returns:
      the error handler.
      Default:
      ""
    • concurrency

      String concurrency
      Set the concurrency of the listener container for this listener. Overrides the default set by the listener container factory. Maps to the concurrency setting of the container type.
      Returns:
      the concurrency.
      Default:
      ""
    • autoStartup

      String autoStartup
      Set to false to not auto start, to override the default setting in the container factory.
      Returns:
      false to not auto start.
      Default:
      ""
    • executor

      String executor
      Set the task executor bean name to use for the listener container; overrides any executor set on the container factory. If a SpEL expression is provided (#{...}), the expression can either evaluate to an executor instance or a bean name.
      Returns:
      the executor bean name.
      Default:
      ""
    • autoAccept

      String autoAccept
      Override the container factory autoAccept property. If a SpEL expression is provided, it must evaluate to a boolean. If the listener method is asynchronous (CompletableFuture, reactor.core.publisher.Mono or Kotlin suspend function), this option is overridden to false by the target AmqpMessageListenerContainer.
      Returns:
      the autoAccept flag.
      Default:
      ""
    • replyPostProcessor

      String replyPostProcessor
      The bean name of a ReplyPostProcessor to post process a response before it is sent. If a SpEL expression is provided (#{...}), the expression can either evaluate to a post-processor instance or a bean name.
      Returns:
      the bean name.
      See Also:
      Default:
      ""
    • messageConverter

      String messageConverter
      Override the container factory's message converter used for this listener. If a SpEL expression is provided (#{...}), the expression can either evaluate to a converter instance or a bean name.
      Returns:
      the message converter bean name.
      Default:
      ""
    • headerMapper

      String headerMapper
      Override the container factory's headerMapper used for this listener. If a SpEL expression is provided (#{...}), the expression can either evaluate to a header mapper instance or a bean name.
      Returns:
      the header mapper bean name.
      Default:
      ""
    • replyContentType

      String replyContentType
      Used to set the content-type of a reply message. Useful when used in conjunction with message converters that can handle multiple content types, such as the ContentTypeDelegatingMessageConverter. SpEL expressions and property placeholders are supported. Also, useful for controlling the final content type property when used with certain converters. This does not apply when the return type is Message or Message; the content-type must be set on the respective message property or header, in those cases.
      Returns:
      the content type.
      Default:
      ""
    • receiveTimeout

      String receiveTimeout
      The timeout for deliveries from the broker in the target AMQP consumer. Can be SpEL expression or properties placeholder-based. Evaluates to long representing milliseconds; or ISO 8601 Duration format.
      Returns:
      the timeout for deliveries from the broker in the target AMQP consumer.
      Default:
      ""
    • gracefulShutdownPeriod

      String gracefulShutdownPeriod
      A duration for how long to wait for all the consumers to shut down successfully on listener container stop. Can be SpEL expression or properties placeholder-based. Evaluates to long representing milliseconds; or ISO 8601 Duration format.
      Returns:
      the duration for how long to wait for all the consumers to shut down.
      Default:
      ""
    • adviceChain

      String[] adviceChain
      The Advice bean names to apply to the listener container.
      Returns:
      the Advice bean names to apply to the listener container.
      See Also:
      Default:
      {}