我有一个Kafka Streams应用程序,该应用程序需要将进入的流加入到全局表中,然后经过一些处理,然后将聚合结果写回到该表中:
KeyValueBytesStoreSupplier supplier = Stores.persistentKeyValueStore(
storeName
);
Materialized<String, String, KeyValueStore<Bytes, byte[]>> m = Materialized.as(
supplier
);
GlobalKTable<String, String> table = builder.globalTable(
topic, m.withKeySerde(
Serdes.String()
).withValueSerde(
Serdes.String()
)
);
stream.leftJoin(
table
...
).groupByKey().aggregate(
...
).toStream().through(
topic, Produced.with(Serdes.String(), Serdes.String())
);
但是,当我尝试流式传输到KTable更新日志时,出现以下错误:Invalid topology: Topic 'topic' has already been registered by another source.
如果我尝试汇总到商店本身,则会出现以下错误:InvalidStateStoreException: Store 'store' is currently closed
。
如何同时针对该表联接并写回其变更日志?
如果无法做到这一点,那么一种解决方案也将可行,该解决方案包括针对存储过滤传入的日志。
答案 0 :(得分:3)
呼叫through()
是的快捷方式
stream.to("topic");
KStream stream2 = builder.stream("topic");
因为您已经使用builder.stream("topic")
,所以您得到Invalid topology: Topic 'topic' has already been registered by another source.
,因为每个主题只能使用一次。如果要将流/主题的数据输入不同的部分,则需要重复使用为此主题创建的原始KStream
:
KStream stream = builder.stream(“ topic”);
// this won't work
KStream stream2 = stream.through("topic");
// rewrite to
stream.to("topic");
KStream stream2 = stream; // or just omit `stream2` and reuse `stream`
不确定您的意思
如果我尝试汇总到商店本身