我想知道在 .toStream() + .to() 的流引用上使用 .through() 重用流的区别
使用 .through()
KStream<String, String> subStream = mainStream
.groupByKey(..)
.aggregate(..)
.toStream(..);
.through("aggregate-topic", ..);
// Then use the (new) stream from .through() to create another topic
对比使用 .toStream() + .to()
KStream<String, String> subStream = mainStream
.groupByKey(..)
.aggregate(..)
.toStream(..);
subStream.to("aggregate-topic", ..);
//reuse the existing subStream from toStream() to create another topic
我已经实现了一个使用后者的功能,因为在我学习 through() 方法之前,这是有意义的。
我现在好奇的是这两种选择的内部情况;选择一个选项而不是另一个选项有什么好处/坏处吗?