Skip to content

Instantly share code, notes, and snippets.

@justdoit0823
Created February 8, 2020 13:57
Show Gist options
  • Save justdoit0823/3d4d2d524ec484dbdf37068d391f04ab to your computer and use it in GitHub Desktop.
Save justdoit0823/3d4d2d524ec484dbdf37068d391f04ab to your computer and use it in GitHub Desktop.
Fetch kafka topic offsets at specified timestamp.
from kafka import KafkaConsumer, TopicPartition
def get_topic_offsets(bootstrap_servers, topic, n_partition, ts):
consumer = KafkaConsumer(bootstrap_servers=bootstrap_servers)
return consumer.offsets_for_times({TopicPartition(topic, i): ts for i in range(n_partition)})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment