Is there a way to consume a message from Kafka topic based on offset. I mean I have a offset id that I previously published in a topic. Now I need get a message from topic based on offset Id which I'm passing.
Kafka - Spring : kafka consumer read a message from topic based on offset
528 views Asked by Anbarasan Nagalingam At
2
There are 2 answers
1
On
Simply use Kafka consumer with required parameters like
- bootstrap-server : (comma separated server names : port no.)
- topic : (topic name)
- partition : (partition number)
- offset : (offset value)
- max-messages : (No. of maximum messages to consume)
sh kafka-console-consumer.sh --bootstrap-server server1:9092,server2:9092,server3:9092 --topic test_topic --partition 0 --offset 43212345 --max-messages 1
Using Java Kafka Consumer Library, However you have to know the partition number also.
Things to consider, the record with your desired offset can be deleted depending of the clean up policy configuration in your Kafka Topic. Remember Kafka is a stream platform. Read the message by offset only if you are debugging.