简体   繁体   English

如何在 Spring Cloud Stream Kafka 绑定中编写订阅主题的方法?

[英]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.

相关问题 春季云流的DLQ分区Kafka主题 - Partitioned Kafka Topic for DLQ for spring-cloud-stream Spring Cloud Stream确定主题Kafka消息来自 - Spring Cloud Stream determine topic Kafka message came from 如何在使用 Spring Cloud Stream 发布到 Kafka 主题之前向消息添加标头 - How to add headers to a message before posting to Kafka Topic using Spring Cloud Stream 如何在 Spring Cloud Stream 中配置函数的绑定以将其输入绑定到 Web 端点并将其输出绑定到 Kafka 主题 - How to configure the bindings of a function in Spring Cloud Stream to bind its input to a web endpoint and its output to a Kafka topic spring cloud stream kafka binder 以编程方式将 kafka 主题(多个分区)偏移量重置为任意数字 - spring cloud stream kafka binder resetting a kafka topic(multiple partitions) offset to an arbitrary number programatically spring-cloud-starter-stream-kafka不会创建提供给spring.boot.cloud.stream.bindings.output.destination的主题 - spring-cloud-starter-stream-kafka does not creates topic provided to spring.boot.cloud.stream.bindings.output.destination Spring 云 Stream Function:调用 Z86408593C34AF77FDD160DF932F8B52<t,r> 通过 REST 调用和 output 它到一个 KAFKA 主题</t,r> - Spring Cloud Stream Function : Invoke Function<T,R> via REST call and output it to a KAFKA Topic spring 云 stream kafka 背压 - spring cloud stream kafka backpressure Spring Cloud 流/Kafka 异常 - Spring cloud stream / Kafka exceptions 使用Spring Cloud Stream阅读主题中的所有消息 - Read all messages in topic with spring cloud stream
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM