3

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.

1 Answers1

3

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

Francis
  • 1,798
  • 1
  • 26
  • 32
Nishu Tayal
  • 20,106
  • 8
  • 49
  • 101