'Is it possible to query a KSQL Table/Materialized view via HTTP?

I have a materialized view created using

CREATE TABLE average_latency AS SELECT DEVICENAME, AVG(LATENCY) AS AVG_LATENCY FROM metrics WINDOW TUMBLING (SIZE 1 MINUTE) GROUP BY DEVICENAME EMIT CHANGES;

I would like to query the table average_latency via a REST API call to get the AVG_LATENCY and DEVICENAME column in the response.

HTTP Client -> KSQL Table/Materialized view

Is this use-case possible? If so, how?



Solution 1:[1]

It is possible to query the internal state store used by Kafka streams by exposing an RPC endpoint on the streams application. Check out the following documentation and examples provided by Confluent.

https://docs.confluent.io/platform/current/streams/developer-guide/interactive-queries.html#streams-developer-guide-interactive-queries-rpc-layer

https://github.com/confluentinc/kafka-streams-examples/blob/7.1.1-post/src/main/java/io/confluent/examples/streams/interactivequeries/kafkamusic/KafkaMusicExample.java

https://github.com/confluentinc/kafka-streams-examples/blob/4.0.x/src/main/java/io/confluent/examples/streams/interactivequeries/kafkamusic/MusicPlaysRestService.java

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1