gpt4 book ai didi

apache-kafka - 流消息到多个主题

转载 作者:行者123 更新时间:2023-12-03 09:23:57 25 4
gpt4 key购买 nike

我有一个主主题,并且有多个谓词,每个谓词都有一个与之关联的输出主题。我想将每个记录发送到谓词解析为true的所有主题。我正在使用Luwak来测试哪个谓词满足记录(要使用此库,您需要评估带有谓词列表的文档,并告诉您哪些匹配-即我只调用一次即可获得满意的谓词列表)。

我正在尝试为此使用Kafka Streams,但似乎在KStream上没有合适的方法(KStream#branch仅将记录路由到单个主题)。

一种可能的方法如下:

Stream from master
Map the values into a format with the original content and the list of matching predicates
Stream to an intermediate with-matches topic

For each predicate/output topic
Stream from intermediate with-matches topic
Filter "does list of matches predicates contain predicate ID"
Map the values to just the original content
Stream to corresponding output topic

这样的中间主题似乎“笨拙”。还有更好的建议吗?

我在用:
  • Kafka v0.10.1.1
  • Luwak v1.4.0
  • 最佳答案

    您可以简单地将多个过滤器并行应用于同一KStream实例:

    KStream stream = ...

    stream.filter(new MyPredicate1()).to("output-topic-1");
    stream.filter(new MyPredicate2()).to("output-topic-2");
    stream.filter(new MyPredicate3()).to("output-topic-3");
    // ... as as many as you need

    每条记录将发送到每个谓词一次-从概念上讲,这是对所有过滤器的广播,但是不会物理复制记录,因此没有内存开销。

    关于apache-kafka - 流消息到多个主题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42388525/

    25 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com