Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Getting latest message timestamp in my Kafka queue

I have Kafka 0.10.0, which, if I understand correctly, adds timestamps to all of the messages. For monitoring purposes, I want to pull out the timestamp of the newest message for a given topic. I did not see an API field for it in any of the Python libraries I have looked at.

like image 697
Konstantin Tarashchanskiy Avatar asked Sep 02 '25 09:09

Konstantin Tarashchanskiy


1 Answers

There is not straightforward method to get the latest message Timestamp from Kafka topics. But the work around is using kafka consumer, and use seek_to_end() to seek the most available offset for partitions.

consumer.seek_to_end()
for message in consumer:
    print(message.timestamp)

You can refer the details here :
https://kafka-python.readthedocs.io/en/master/apidoc/KafkaConsumer.html#kafka.KafkaConsumer.seek_to_end

like image 197
Nishu Tayal Avatar answered Sep 04 '25 23:09

Nishu Tayal