【问题标题】:How do you send the record matching certain condition/s to specific/multiple output topics in Spring apache-kafka?如何将匹配特定条件的记录发送到 Spring apache-kafka 中的特定/多个输出主题?
【发布时间】:2022-01-06 03:23:34
【问题描述】:

I have referred this. but, this is an old post so i'm looking for a better solution if any.

我有一个包含“userActivity”数据的输入主题。现在,我希望根据 userInterest、userSubscribedGroup、userChoice 等收集不同的分析结果,这些分析结果来自同一个 Kafka-streams-application 的不同输出主题。

你能帮我实现这个吗... ps:这是我第一次使用 Kafka-streams,所以我不知道还有其他选择。

编辑:

有可能一条记录匹配多个条件,在这种情况下,相同的记录也应该进入这些输出主题。

if(record1 matches criteria1) then... output to topic1;
if(record1 matches criteria2) then ... output to topic2;
and so on.
note: i'm not looking elseIf kind of solution.

【问题讨论】:

    标签: apache-kafka apache-kafka-streams spring-kafka


    【解决方案1】:

    用于在运行时根据每条记录的键值对动态选择要发送到的主题。 Apache Kafka 2.0 或更高版本引入了一个名为:Dynamic routing

    这是一个例子:https://kafka-tutorials.confluent.io/dynamic-output-topic/confluent.html

    【讨论】:

    • 好的,谢谢,我知道通过这种方法,一条记录可以进入其中一个输出主题。同一条记录不能进入多个主题。我说的对吗?
    • 实际上,我正在寻找一种方法,如果它符合某些条件,则可以将相同的记录发送到多个主题中。
    • 我已经编辑了问题以便更好地理解
    • 您的用例,实际上,对于每个if(recordX matches criteriaN) then... output to topicN;,我将创建一个KStream 实例,其中.filter 是IF 子句中的条件过滤器,.to(topicN)
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2011-02-15
    • 1970-01-01
    • 2016-06-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多