我想写一个消费者方法,使用KafkaListener订阅一个主题。
我找到了一个答案,它建议这样做------。
@KafkaListener(id = "foo", topics = "dead-out")
public void dlq(Message<?> in) {
System.out.println("DLQ:" + in);
}
现在,在注释中,"topics "是被订阅的主题的名称,但 "id "字段是什么?但是'id'字段是什么?或者有什么更好的方法吗?
感谢你的帮助。
@KafkaListener
与Spring Cloud Stream无关;它在Spring for Apache Kafka项目中(Spring Cloud Stream使用它的Kafka binder)。
请参阅javadocs
/**
* The unique identifier of the container managing for this endpoint.
* <p>If none is specified an auto-generated one is provided.
* <p>Note: When provided, this value will override the group id property
* in the consumer factory configuration, unless {@link #idIsGroup()}
* is set to false.
* <p>SpEL {@code #{...}} and property place holders {@code ${...}} are supported.
* @return the {@code id} for the container managing for this endpoint.
* @see org.springframework.kafka.config.KafkaListenerEndpointRegistry#getListenerContainer(String)
*/
String id() default "";
该 id
也用于从监听器容器的 KafkaListenerEndpointRegistry
豆子,所以你可以 stop()
和 start()
它。
如果你想使用spring-cloud-stream,请阅读它的文档。