简体   繁体   English

Spring Cloud Stream确定主题Kafka消息来自

[英]Spring Cloud Stream determine topic Kafka message came from

My @StreamListener listening for multiple Kafka topics(totally like 10 topics) specified in spring.cloud.stream.bindings.input.destination property. 我的@StreamListener侦听spring.cloud.stream.bindings.input.destination属性中指定的多个Kafka主题( 总计类似于10个主题)。

Is there any way to determine the topic message came from inside the @StreamListener annotated method? 有什么方法可以确定主题消息来自@StreamListener带注释的方法内部吗? I wouldn't like to configure bindings for all topics separately and write 10 almost identical StreamListeners. 我不想为所有主题分别配置绑定并编写10个几乎相同的StreamListeners。

See KafkaHeaders. RECEIVED_TOPIC 参见KafkaHeaders. RECEIVED_TOPIC KafkaHeaders. RECEIVED_TOPIC you can specify a separate parameter on the @StreamListener method. KafkaHeaders. RECEIVED_TOPIC可以在@StreamListener方法上指定一个单独的参数。 Something like this in Spring Kafka docs: Spring Kafka文档中的内容如下:

@KafkaListener(id = "qux", topicPattern = "myTopic1")
public void listen(@Payload String foo,
    @Header(KafkaHeaders.RECEIVED_MESSAGE_KEY) Integer key,
    @Header(KafkaHeaders.RECEIVED_PARTITION_ID) int partition,
    @Header(KafkaHeaders.RECEIVED_TOPIC) String topic,
    @Header(KafkaHeaders.RECEIVED_TIMESTAMP) long ts
        ) {
    ...
}

https://docs.spring.io/spring-kafka/reference/htmlsingle/#kafka-listener-annotation https://docs.spring.io/spring-kafka/reference/htmlsingle/#kafka-listener-annotation

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何在使用 Spring Cloud Stream 发布到 Kafka 主题之前向消息添加标头 - How to add headers to a message before posting to Kafka Topic using Spring Cloud Stream 春季云流的DLQ分区Kafka主题 - Partitioned Kafka Topic for DLQ for spring-cloud-stream 如何在 Spring Cloud Stream Kafka 绑定中编写订阅主题的方法? - How to write a method subscribing to a topic in Spring Cloud Stream Kafka binding? 如何确定Kafka消息的主题 - How to determine topic for a Kafka message 默认情况下如何使用Kafka Spring Cloud Stream并使用汇合API生成的Kafka消息? - How to consume from Kafka Spring Cloud Stream by default and also consume a Kafka message generated by the confluent API? spring cloud stream kafka binder 以编程方式将 kafka 主题(多个分区)偏移量重置为任意数字 - spring cloud stream kafka binder resetting a kafka topic(multiple partitions) offset to an arbitrary number programatically Spring 云 Stream:如何从 REST Z594C103F2C6E04E0C3DAZ8 生成 Kafka 消息? - Spring Cloud Stream: how can I produce a Kafka message from a REST controller? 使用Kafka向Dlq Spring云流发送消息时出错 - Error sending message to Dlq Spring cloud stream with Kafka 使用spring cloud stream kafka读取消息的编程方式 - Programmatic way to read message using spring cloud stream kafka 如何根据条件向2个kafka主题发布消息 - spring cloud stream - How to publish message to 2 kafka topics based on condition - spring cloud stream
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM