[英]How to write a method subscribing to a topic in Spring Cloud Stream Kafka binding?
I want to write a consumer method which subscribes to a topic using KafkaListener.我想编写一个使用 KafkaListener 订阅主题的消费者方法。
I found an answer which suggested this -我找到了一个建议这个的答案 -
@KafkaListener(id = "foo", topics = "dead-out")
public void dlq(Message<?> in) {
System.out.println("DLQ:" + in);
}
Now, in the annotation 'topics' is the name of the subscribed topic.现在,注释中的“主题”是订阅主题的名称。 But what is 'id' field?但什么是“id”字段? Or is there a better way?或者,还有更好的方法?
Your help is appreciated.感谢您的帮助。
@KafkaListener
has nothing to do with Spring Cloud Stream; @KafkaListener
与 Spring Cloud Stream 无关; it is in the Spring for Apache Kafka project (which Spring Cloud Stream uses for its Kafka binder).它位于 Spring 中,用于 Apache Kafka 项目(其中 Spring Cloud ZEAE835E83C0494A37692Z29F2 用于其卡夫卡)。
See the javadocs请参阅 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 "";
The id
is also used to get the listener container from the KafkaListenerEndpointRegistry
bean so you can stop()
and start()
it.该id
还用于从KafkaListenerEndpointRegistry
bean 获取侦听器容器,以便您可以stop()
和start()
它。
If you want to use spring-cloud-stream instead;如果您想改用 spring-cloud-stream ; read its documentation.阅读其文档。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.