I am trying to work on an interactive queries app for Kafka Streams. Its a simple count() based state store. 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. I have a REST endpoint for interactive queries
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. 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. For regular KTable only part of the whole dataset is available.
You need to lookup for key metadata and redirect REST call to the corresponding instance as described here .
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.