python-3.x - Python KafkaConsumer 从时间戳开始消费消息

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

最佳答案

我猜你正在使用 kafka-python ( https://github.com/dpkp/kafka-python ),正如你提到的“KafkaConsumer”。

您可以使用 offsets_for_times() 方法来检索与时间戳匹配的偏移量。 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

希望这对您有所帮助!

https://stackoverflow.com/questions/46402672/

相关文章:

typescript - TypeScript 有 toString() 版本吗

arrays - 测试值是否在列表/数组中 (Ti-Basic)

php - Laravel - 使用 Query Builder 函数传递变量

regex - 如何提取ansible变量中的最后一个数字

c# - 可访问性不一致 : field type is less accessible than

python-2.7 - 如何删除回复键盘( Telegram Bot )

apache-kafka - Zookeeper 安装在 Windows 10 上不起作用

bash - 在 MAC OSX 中比较 Bash 中的两个日期

arrays - Perl:在哈希数组中找到最大值和最小值

regex - RegExp 字符类中的范围乱序