简体   繁体   中英

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.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM