@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 |
---|---|
String |
admin
Reference to a
RabbitAdmin . |
QueueBinding[] |
bindings
Array of
QueueBinding s providing the listener's queue names, together
with the exchange and optional binding information. |
String |
containerFactory
The bean name of the
RabbitListenerContainerFactory
to use to create the message listener container responsible to serve this endpoint. |
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. |
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> . |
String |
id
The unique identifier of the container managing for this endpoint.
|
String |
priority
The priority of this endpoint.
|
String[] |
queues
The queues for this listener.
|
public abstract 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 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 String[] queues
Queue
object.
Mutually exclusive with bindings()
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 String priority
public abstract 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.public abstract String group
Collection<MessageListenerContainer>
.
This allows, for example, iteration over the collection to start/stop a subset
of containers.