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