Python KafkaConsumer开始使用时间戳中的消息

Python KafkaConsumer开始使用时间戳中的消息

问题描述:

我打算跳过主题的开头,只阅读从特定时间戳记到结尾的消息.关于如何实现这一目标的任何提示?

I'm planning to skip the start of the topic and only read messages from a certain timestamp to the end. Any hints on how to achieve this?

我猜您正在使用kafka-python(

I'm guessing you are using kafka-python (https://github.com/dpkp/kafka-python) as you mentioned "KafkaConsumer".

您可以使用offsets_for_times()方法来检索与时间戳匹配的偏移量. https://kafka-python.readthedocs.io /en/master/apidoc/KafkaConsumer.html#kafka.KafkaConsumer.offsets_for_times

You can use the offsets_for_times() method to retrieve the offset that matches a timestamp. https://kafka-python.readthedocs.io/en/master/apidoc/KafkaConsumer.html#kafka.KafkaConsumer.offsets_for_times

紧随其后的是使用seek()寻求该偏移量. https://kafka-python.readthedocs.io /en/master/apidoc/KafkaConsumer.html#kafka.KafkaConsumer.seek

Following that just seek to that offset using seek(). https://kafka-python.readthedocs.io/en/master/apidoc/KafkaConsumer.html#kafka.KafkaConsumer.seek

希望这会有所帮助!