【发布时间】:2018-09-20 13:50:56
【问题描述】:
在使用 Kafka Streams DSL 时,有没有办法将同一主题用作两个不同处理例程的源?
StreamsBuilder streamsBuilder = new StreamsBuilder();
// use the topic as a stream
streamsBuilder.stream("topic")...
// use the same topic as a source for KTable
streamsBuilder.table("topic")...
return streamsBuilder.build();
上面的简单实现在运行时抛出TopologyException:无效拓扑:主题主题已被另一个来源注册。如果我们深入了解底层处理器 API,这是完全有效的。使用它是唯一的出路吗?
更新: 到目前为止我发现的最接近的替代方案:
StreamsBuilder streamsBuilder = new StreamsBuilder();
final KStream<Object, Object> stream = streamsBuilder.stream("topic");
// use the topic as a stream
stream...
// create a KTable from the KStream
stream.groupByKey().reduce((oldValue, newValue) -> newValue)...
return streamsBuilder.build();
【问题讨论】:
标签: apache-kafka apache-kafka-streams