java如何在Spring Cloud Stream Kafka binding中编写订阅主题的方法?
我想写一个消费者方法,用KafkaListener订阅一个主题
我找到了一个答案,表明了这一点-
@KafkaListener(id = "foo", topics = "dead-out")
public void dlq(Message<?> in) {
System.out.println("DLQ:" + in);
}
现在,注释中的“主题”是订阅主题的名称。但什么是“id”字段?还是有更好的方法
谢谢你的帮助
# 1 楼答案
@KafkaListener
与春云流无关;这是ApacheKafka项目的春天(SpringCloudStream将其用于Kafka活页夹)参见javadocs
id
还用于从KafkaListenerEndpointRegistry
bean获取侦听器容器,这样您就可以stop()
和start()
访问它如果你想改用spring cloud stream;阅读它的文档