|
该版本仍在开发中,尚未被视为稳定。对于最新稳定版本,请使用 Spring for Apache Kafka 4.0.0! |
@KafkaListener作为元注释
从2.2版本开始,你现在可以使用@KafkaListener作为一种元注释。
以下示例展示了如何实现:
@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";
}
你必须至少使用其中一个别名主题,主题模式或主题分区(而且,通常,身份证或组ID除非你指定了group.id在消费级工厂配置中)。
以下示例展示了如何实现:
@MyThreeConsumersListener(id = "my.group", topics = "my.topic")
public void listen1(String in) {
...
}