Get the latest message from the kafka script consumer console

We can receive all messages from Kafka by doing:

bin/kafka-console-consumer.sh --zookeeper localhost:2181 --topic test --from-beginning 

Is there a way to get only the last message ?

EDIT:

If you just want to keep track of some messages ( --max-messages 10 ) in your stream, a convenient command is:

watch -n5 "./bin/kafka-console-consumer.sh --zookeeper localhost:2181 --topic auction --max-messages 10"

+5
source share
2 answers

I think it will work with the following command line (i.e. without -from-begining):

 bin/kafka-console-consumer.sh --zookeeper localhost:2181 --topic test 
+2
source

I probably got the correct answer from some googling http://grokbase.com/t/kafka/users/145x930s27/how-to-get-last-message

There, someone suggests finding the last offset with getOffsetBefore api, and then using this offset - 1 to retrieve.

+2
source

Source: https://habr.com/ru/post/1233867/


All Articles