gpt4 book ai didi

java - Apache 卡夫卡 (KStreams) : How to subscribe to multiple topics?

转载 作者:行者123 更新时间:2023-11-30 10:02:50 24 4
gpt4 key购买 nike

我有以下代码

//Kafka Config setup
Properties props = ...; //setup

List<String> topicList = Arrays.asList({"A", "B", "C"});

StreamBuilder builder = new StreamBuilder();
KStream<String, String> source = builder.stream(topicList);

source
.map((k,v) -> { //busy code for mapping data})
.transformValues(new MyGenericTransformer());
.to((k,v,r) -> {//busy code for topic routing});

new KafkaStream(builder.build(), properties).start();

我的问题: 当我添加多个主题订阅时(即上面的 A、B、C),Kstream 代码停止接收记录。

引用文献: https://kafka.apache.org/10/javadoc/org/apache/kafka/streams/StreamsBuilder.html

相关文档

public <K,V> KStream<K,V> stream(java.util.Collection<java.lang.String> topics)

"If multiple topics are specified there is no ordering guarantee for records from different topics."

我想要实现的目标:让一个 Kstream(即上面的“来源”)消费/处理多个主题。

最佳答案

主题是否共享相同的 key ?

Note that the specified input topics must be partitioned by key. If this is not the case it is the user's responsibility to repartition the data before any key based operation (like aggregation or join) is applied to the returned KStream.

这可能是你的障碍。

另一个可能的问题可能是使用的消费者组。

关于java - Apache 卡夫卡 (KStreams) : How to subscribe to multiple topics?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56547353/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com