Get last message from kafka consumer console script

I’m not aware of any automatism, but using this simple two step approach, it should work.
Note that in my case it was a partitioned topic, you can leave the params for it out in case you have a unpartitioned one:

1) Get max offset for your topic (+ their partitions):

bin/kafka-run-class.sh kafka.tools.GetOffsetShell --broker-list localhost:9092 --topic mytopic

mytopic:2:11
mytopic:1:7
mytopic:0:15
mytopic:3:8

2) Choose a topic (+ partition) and provide the offset – n as parameter:

bin/kafka-console-consumer.sh --bootstrap-server localhost:9092 --topic mytopic --offset 10 --partition 0  

The last n messages of the topic will be printed to the console.
In my example, it will show 5 messages (= 15-10).

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)