简体   繁体   English

Spring和Kafka:加入3个Kafka主题以生成输出Kafka流

[英]Spring and Kafka: Join 3 Kafka topics to generate output Kafka streams

I have a requirement to join 3 Kafka topics. 我要求加入3个Kafka主题。 First two topic A and B will be added using inner join as the message key is same and generate a new Kafka stream with POJO same as B. Now with this accumulated stream, I need to join another topic C and I need to group the output based on a field , which is present in C. 前两个主题A和B将使用内连接添加,因为消息密钥相同,并生成一个新的Kafka流,POJO与B相同。现在有了这个累积的流,我需要加入另一个主题C,我需要对输出进行分组基于C中存在的字段

So far I have below approach for this : 到目前为止,我有以下方法:

KStream - KStream inner join for first two topic ( A and B) Will it be possible to not publish this accumulated output on any topic and still be able to use it below KStream - 前两个主题(A和B)的KStream内连接是否可以不在任何主题上发布此累积输出,仍然可以在下面使用它

KStream - KStream (Above accumulated stream and topic C) KStream - KStream(以上累积流和主题C)

Could you please suggest a better approach or any examples that I can look on similar implementation in java. 你能否提出一个更好的方法或任何我可以在java中看到类似实现的例子。

You can use two consecutive joins: 您可以使用两个连续的连接:

KStream streamAB = streamA.join(streamB, ...);
// either:
KStream streamABC = streamA.selectKey(...) // set to the key as in streamC
                           .join(streamC, ...);
// or:
KStream streamCNew = streamC.selectKey(...); // set to the key as in streamAB
KStream streamABC = streamA.join(streamCnew, ...);
// or:
KStream streamCNew = streamC.selectKey(...); // set to a new join key
KStream streamABC = streamA.selectKey(...) // set to a new join key
                           .join(streamC, ...);

streamABC.selectKey(/* extract grouping field and set as key */).to("outputTopic");

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM