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.
Asked
Active
Viewed 6,571 times
3
-
In a regular consumer from the latest offset, you just get the timestamp. However, how do you define "latest" when you start getting more than one event per second? As soon as you query the data, it's stale... – OneCricketeer Dec 19 '18 at 15:19
-
@cricket_007 This is for monitoring purposes. I don't care what exactly the contents of the latest message is, just what the timestamp is on it (to some rough granularity). – Konstantin Tarashchanskiy Dec 19 '18 at 17:25
-
I wasn't mentioning anything about the content, though :) – OneCricketeer Dec 19 '18 at 17:33
-
Four years later... you can use `consumer.end_offsets()` now – kbridge4096 May 26 '22 at 07:01
1 Answers
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