简体   繁体   English

如何使用交互式查询存储和全局存储实现处理单个主题的 Kafka Streams 拓扑

[英]How to implement Kafka Streams topology that process single topic with interactive queries store and global store

I am trying to implement Kafka Streams that is going to treat single topic stream as global database with interactive queries possible.我正在尝试实现 Kafka Streams,它将单个主题流视为具有交互式查询可能的全局数据库。 So I want to have:所以我想要:

  1. global store for records (GlobalKTable, KeyValueStore)记录的全局存储(GlobalKTable、KeyValueStore)

  2. queryable store, that allows me to get result of an interactive query (maximum)可查询存储,允许我获得交互式查询的结果(最大)

Interactive query has to calculate the global maximum of one of record's field:交互式查询必须计算记录字段之一的全局最大值:

 KStream<String, TercUnitRecord> recordsStream = topologyBuilder.stream(topicName);
 KTable<String, Long> lastUpdateStore = recordsStream.mapValues(record -> record.getLastUpdate())
                .selectKey((key, value) -> "lastdate")
                .groupByKey(Grouped.with(Serdes.String(), Serdes.Long()))
                .reduce((maxValue, currValue) -> maxValue.compareTo(currValue) == 1 ? maxValue : currValue,
 Materialized.as("terc-lastupdate"));

However, I am facing problem that I cannot use the same single topic as source in one Kafka Streams instance.但是,我面临的问题是我无法在一个 Kafka Streams 实例中使用与源相同的单个主题。 I have done a reasearch and the only way I found to do this is by multiple KafkaStreams instances, but I am not sure it is the correct and only way to achieve this.我已经进行了研究,我发现这样做的唯一方法是通过多个 KafkaStreams 实例,但我不确定这是实现这一目标的正确且唯一的方法。 Any ideas?有任何想法吗?

我为每个任务使用了多个 KafkaStreams 实例并且它工作正常。

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

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