@Target(value={TYPE,METHOD,ANNOTATION_TYPE})
@Retention(value=RUNTIME)
@MessageMapping
@Documented
@Repeatable(value=KafkaListeners.class)
public @interface KafkaListener
containerFactory()
identifies the KafkaListenerContainerFactory to use to build the Kafka listener container. If not
set, a default container factory is assumed to be available with a bean
name of kafkaListenerContainerFactory unless an explicit default has been
provided through configuration.
Processing of @KafkaListener annotations is performed by
registering a KafkaListenerAnnotationBeanPostProcessor. This can be
done manually or, more conveniently, through EnableKafka annotation.
Annotated methods are allowed to have flexible signatures similar to what
MessageMapping provides, that is
ConsumerRecord to
access to the raw Kafka messageAcknowledgment to manually ack@Payload-annotated method
arguments including the support of validation@Header-annotated method
arguments to extract a specific header value, defined by
KafkaHeaders@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
for convenient access to all method arguments.When defined at the method level, a listener container is created for each method. The
MessageListener is a MessagingMessageListenerAdapter, configured with a
MethodKafkaListenerEndpoint.
When defined at the class level, a single message listener container is used to service
all methods annotated with @KafkaHandler. 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 MultiMethodKafkaListenerEndpoint.
EnableKafka,
KafkaListenerAnnotationBeanPostProcessor,
KafkaListeners| Modifier and Type | Optional Element and Description |
|---|---|
java.lang.String |
containerFactory
The bean name of the
KafkaListenerContainerFactory
to use to create the message listener container responsible to serve this endpoint. |
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.
|
TopicPartition[] |
topicPartitions
The topicPartitions for this listener.
|
java.lang.String |
topicPattern
The topic pattern for this listener.
|
java.lang.String[] |
topics
The topics for this listener.
|
public abstract java.lang.String id
If none is specified an auto-generated one is provided.
id for the container managing for this endpoint.KafkaListenerEndpointRegistry.getListenerContainer(String)public abstract java.lang.String containerFactory
KafkaListenerContainerFactory
to use to create the message listener container responsible to serve this endpoint.
If not specified, the default container factory is used, if any.
public abstract java.lang.String[] topics
topicPattern() and topicPartitions().public abstract java.lang.String topicPattern
topics() and topicPartitions().public abstract TopicPartition[] topicPartitions
topicPattern() and topics().public abstract java.lang.String group
Collection<MessageListenerContainer>.
This allows, for example, iteration over the collection to start/stop a subset
of containers.