@Target(value={TYPE,METHOD,ANNOTATION_TYPE}) @Retention(value=RUNTIME) @MessageMapping @Documented @Repeatable(value=RabbitListeners.class) public @interface RabbitListener
queues()
(or bindings()
). The containerFactory()
identifies the
RabbitListenerContainerFactory
to use to build the rabbit listener container. If not
set, a default container factory is assumed to be available with a bean name
of rabbitListenerContainerFactory
unless an explicit default has been provided
through configuration.
Processing of @RabbitListener
annotations is performed by registering a
RabbitListenerAnnotationBeanPostProcessor
. This can be done manually or, more
conveniently, through the <rabbit:annotation-driven/>
element or
EnableRabbit
annotation.
Annotated methods are allowed to have flexible signatures similar to what
MessageMapping
provides, that is
Channel
to get access to the ChannelMessage
or one if subclass to get access to
the raw AMQP messageMessage
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.
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.
When bindings()
are provided, and the application context contains a
RabbitAdmin
, the queue, exchange and
binding will be automatically declared.
When defined at the method level, a listener container is created for each method.
The MessageListener
is a
MessagingMessageListenerAdapter
,
configured with a
MethodRabbitListenerEndpoint
.
When defined at the class level, a single message listener container is used to
service all methods annotated with @RabbitHandler
. Method signatures of such
annotated methods must not cause any ambiguity such that a single method can be
resolved for a particular inbound message. The
MessagingMessageListenerAdapter
is configured with a
MultiMethodRabbitListenerEndpoint
.
EnableRabbit
,
RabbitListenerAnnotationBeanPostProcessor
,
RabbitListeners
Modifier and Type | Optional Element and Description |
---|---|
java.lang.String |
ackMode
Override the container factory
AcknowledgeMode property. |
java.lang.String |
admin
Reference to a
RabbitAdmin . |
java.lang.String |
autoStartup
Set to true or false, to override the default setting in the container factory.
|
QueueBinding[] |
bindings
Array of
QueueBinding s providing the listener's queue names, together
with the exchange and optional binding information. |
java.lang.String |
concurrency
Set the concurrency of the listener container for this listener.
|
java.lang.String |
containerFactory
The bean name of the
RabbitListenerContainerFactory
to use to create the message listener container responsible to serve this endpoint. |
java.lang.String |
errorHandler
Set an
RabbitListenerErrorHandler to
invoke if the listener method throws an exception. |
boolean |
exclusive
When
true , a single consumer in the container will have exclusive use of the
queues() , preventing other consumers from receiving messages from the
queues. |
java.lang.String |
executor
Set the task executor bean name to use for this listener's container; overrides
any executor set on the container factory.
|
java.lang.String |
group
If provided, the listener container for this listener will be added to a bean
with this value as its name, of type
Collection<MessageListenerContainer> . |
java.lang.String |
id
The unique identifier of the container managing for this endpoint.
|
java.lang.String |
priority
The priority of this endpoint.
|
java.lang.String[] |
queues
The queues for this listener.
|
Queue[] |
queuesToDeclare
The queues for this listener.
|
java.lang.String |
replyPostProcessor
The bean name of a
ReplyPostProcessor to post
process a response before it is sent. |
java.lang.String |
returnExceptions
Set to "true" to cause exceptions thrown by the listener to be sent to the sender
using normal
replyTo/@SendTo semantics. |
public abstract java.lang.String id
If none is specified an auto-generated one is provided.
id
for the container managing for this endpoint.RabbitListenerEndpointRegistry.getListenerContainer(String)
public abstract java.lang.String containerFactory
RabbitListenerContainerFactory
to use to create the message listener container responsible to serve this endpoint.
If not specified, the default container factory is used, if any.
RabbitListenerContainerFactory
bean name.public abstract java.lang.String[] queues
Queue
object.
The queue(s) must exist, or be otherwise defined elsewhere as a bean(s) with
a RabbitAdmin
in the application
context.
Mutually exclusive with bindings()
and queuesToDeclare()
.MessageListenerContainer
public abstract Queue[] queuesToDeclare
RabbitAdmin
in the
application context, the queue will be declared on the broker with default
binding (default exchange with the queue name as the routing key).
Mutually exclusive with bindings()
and queues()
.MessageListenerContainer
public abstract boolean exclusive
true
, a single consumer in the container will have exclusive use of the
queues()
, preventing other consumers from receiving messages from the
queues. When true
, requires a concurrency of 1. Default false
.exclusive
boolean flag.public abstract java.lang.String priority
public abstract java.lang.String admin
RabbitAdmin
. Required if the listener is using auto-delete
queues and those queues are configured for conditional declaration. This
is the admin that will (re)declare those queues when the container is
(re)started. See the reference documentation for more information.RabbitAdmin
bean name.public abstract QueueBinding[] bindings
QueueBinding
s providing the listener's queue names, together
with the exchange and optional binding information.
Mutually exclusive with queues()
and queuesToDeclare()
.MessageListenerContainer
public abstract java.lang.String group
Collection<MessageListenerContainer>
.
This allows, for example, iteration over the collection to start/stop a subset
of containers.public abstract java.lang.String returnExceptions
replyTo/@SendTo
semantics. When false, the exception is thrown
to the listener container and normal retry/DLQ processing is performed.RemoteInvocationAwareMessageConverterAdapter
the exception will be re-thrown.
Otherwise, the sender will receive a RemoteInvocationResult
wrapping the
exception.public abstract java.lang.String errorHandler
RabbitListenerErrorHandler
to
invoke if the listener method throws an exception. A simple String representing the
bean name. If a Spel expression (#{...}) is provided, the expression must
evaluate to a bean name or a
RabbitListenerErrorHandler
instance.public abstract java.lang.String concurrency
For a
SimpleMessageListenerContainer
if this value is a simple integer, it sets a fixed
number of consumers in the concurrentConsumers
property. If it is a string
with the form "m-n"
, the concurrentConsumers
is set to m
and the maxConcurrentConsumers
is set to n
.
For a
DirectMessageListenerContainer
it sets the consumersPerQueue
property.
public abstract java.lang.String autoStartup
public abstract java.lang.String executor
public abstract java.lang.String ackMode
AcknowledgeMode
property. Must be one of the
valid enumerations. If a SpEL expression is provided, it must evaluate to a
String
or AcknowledgeMode
.public abstract java.lang.String replyPostProcessor
ReplyPostProcessor
to post
process a response before it is sent.AbstractAdaptableMessageListener.setReplyPostProcessor(org.springframework.amqp.rabbit.listener.adapter.ReplyPostProcessor)