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

编程入门 行业动态 更新时间:2024-10-28 06:21:07
本文介绍了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( github/dpkp/kafka-python ),当您提到"KafkaConsumer"时.

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

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

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

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

希望这会有所帮助!

更多推荐

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

本文发布于:2023-10-28 08:55:08,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1536152.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:消息   时间   Python   KafkaConsumer

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!