Python KafkaConsumer开始使用时间戳中的消息 [英] Python KafkaConsumer start consuming messages from a timestamp

查看:535
本文介绍了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

希望这会有所帮助!

这篇关于Python KafkaConsumer开始使用时间戳中的消息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆