bm1*_*729 7 apache-kafka apache-kafka-streams
我有一个主要主题和多个谓词,每个谓词都有一个与之关联的输出主题.我想将每条记录发送到其谓词解析为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
Run Code Online (Sandbox Code Playgroud)
然而,这样一个中间话题似乎"笨拙".有更好的建议吗?
我在用:
Mat*_*Sax 14
您可以简单地将多个过滤器并行应用于同一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
Run Code Online (Sandbox Code Playgroud)
每条记录将被发送到每个谓词一次 - 它在概念上是对所有过滤器的广播,但记录不会被物理复制,因此没有内存开销.
| 归档时间: |
|
| 查看次数: |
4162 次 |
| 最近记录: |