How do I get the the offset of last message of a Kafka topic using confluent-kafka-python?

I need to retrive last N messages of a topic using confluent-kafka-python .

I’ve been reading confluent_kafka API — confluent-kafka 1.9.0 documentation for a day, but no finding any appropriate method for getting the offset of the last message, thus I cannot calculate the offset for consumer to start with.

Please help. Thanks!

Get the high watermarks of each partition you want to consume, then subtract N and seek

https://docs.confluent.io/platform/current/clients/confluent-kafka-python/html/index.html#confluent_kafka.Consumer.get_watermark_offsets

1 Like