我打算跳过主题的开头,只阅读从某个时间戳到结尾的消息。关于如何实现这一目标的任何提示?
最佳答案
我猜你正在使用 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/