Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Query Kafka topic for specific record

Tags:

apache-kafka

Is there an elegant way to query a Kafka topic for a specific record? The REST API that I'm building gets an ID and needs to look up records associated with that ID in a Kafka topic. One approach is to check every record in the topic via a custom consumer and look for a match, but I'd like to avoid the overhead of reading a bunch of records. Does Kafka have a fast, built in filtering capability?

like image 684
user554481 Avatar asked Feb 29 '16 22:02

user554481


People also ask

How do I query data from a Kafka topic?

The only fast way to search for a record in Kafka (to oversimplify) is by partition and offset. The new producer class can return, via futures, the partition and offset into which a message was written. You can use these two values to very quickly retrieve the message.

Is it possible to query a Kafka topic?

When navigating to a Kafka topic, you can query all existing data and the live stream. Lenses immediately presents a snapshot of the latest data in table browsing mode allowing: To Filter by timestamp, offset or partition. To Drill into the data and expand the key and value payloads and any nested fields.

Can we query data from Kafka?

Yes, you can do it with interactive queries. You can create a kafka stream to read the input topic and generate a state store ( in memory/rocksdb and synchronize with kafka ). This state store is queryable by key ( ReadOnlyKeyValueStore ).

Which command is used in Kafka to retrieve messages from a topic?

Kafka provides the utility kafka-console-consumer.sh which is located at ~/kafka-training/kafka/bin/kafka-console-producer.sh to receive messages from a topic on the command line.


1 Answers

The only fast way to search for a record in Kafka (to oversimplify) is by partition and offset. The new producer class can return, via futures, the partition and offset into which a message was written. You can use these two values to very quickly retrieve the message.

So if you make the ID out of the partition and offset then you can implement your fast query. Otherwise, not so much. This means that the ID for an object isn't part of your data model, but rather is generated by the Kafka-knowledgable code.

Maybe that works for you, maybe it doesn't.

like image 53
Chris Gerken Avatar answered Oct 18 '22 19:10

Chris Gerken