此版本仍在开发中,尚未被视为稳定版本。对于最新的稳定版本,请使用 Spring for Apache Kafka 3.3.0! |
@KafkaListener
作为元注释
从版本 2.2 开始,您现在可以使用@KafkaListener
作为 meta 注释。
以下示例显示了如何执行此作:
@Target(ElementType.METHOD)
@Retention(RetentionPolicy.RUNTIME)
@KafkaListener
public @interface MyThreeConsumersListener {
@AliasFor(annotation = KafkaListener.class, attribute = "id")
String id();
@AliasFor(annotation = KafkaListener.class, attribute = "topics")
String[] topics();
@AliasFor(annotation = KafkaListener.class, attribute = "concurrency")
String concurrency() default "3";
}
您必须为以下至少一个topics
,topicPattern
或topicPartitions
(而且,通常id
或groupId
除非您指定了group.id
在 Consumer Factory 配置中)。
以下示例显示了如何执行此作:
@MyThreeConsumersListener(id = "my.group", topics = "my.topic")
public void listen1(String in) {
...
}