简体   繁体   English

Kafka Streams KV 状态存储中的空值

[英]Null value in Kafka Streams KV state store

I am trying to work on an interactive queries app for Kafka Streams.我正在尝试为 Kafka Streams 开发交互式查询应用程序。 Its a simple count() based state store.它是一个简单的基于 count() 的状态存储。 but the problem I see is that as soon as I scale the app to more than one instance, I start getting null values for some of the keys但我看到的问题是,一旦我将应用程序扩展到多个实例,我就会开始为某些键获取空值

KStream<String, String> inputStream = builder.stream(INPUT_TOPIC, Consumed.with(Serdes.String(), Serdes.String())); //key: foo, value:bar
inputStream.groupByKey(Grouped.with(Serdes.String(), Serdes.String()))
                .count(Materialized.<String, Long, KeyValueStore<Bytes, byte[]>>as(STATE_STORE_NAME)
                        .withKeySerde(Serdes.String())
                        .withValueSerde(Serdes.Long()));

That's pretty much it in terms of the test DSL based pipeline.就基于测试 DSL 的管道而言,差不多就是这样。 I have a REST endpoint for interactive queries我有一个用于交互式查询的 REST 端点

KafkaStreams streams = ...;
ReadOnlyKeyValueStore<String, Long> averageStore = streams.store(storeName, QueryableStoreTypes.<String, Long>keyValueStore());
Long count = averageStore.get(word);

count is null - this behavior is for some keys only. count为空 - 此行为仅适用于某些键。 And this is irrespective of whether or not the key is present locally这与本地是否存在密钥无关

When you scale your Kafka Streams application only global tables are visible on all instances.当您扩展 Kafka Streams 应用程序时,只有全局表在所有实例上可见。 For regular KTable only part of the whole dataset is available.对于常规 KTable,只有整个数据集的一部分可用。

You need to lookup for key metadata and redirect REST call to the corresponding instance as described here .您需要查找关键元数据并将 REST 调用重定向到此处所述的相应实例。

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

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