使用者重启后,kafka-python从最后产生的消息中读取 [英] kafka-python read from last produced message after a consumer restart

查看:269
本文介绍了使用者重启后,kafka-python从最后产生的消息中读取的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 kafka-python 来吸收来自kafka队列的消息(kafka版本0.10 .2.0).特别是我正在使用 KafkaConsumer 类型. 如果使用者停止并且在一段时间后重新启动,我想从最新产生的消息重新开始,即删除使用者停机期间产生的所有消息. 我该如何实现?

i am using kafka-python to consume messages from a kafka queue (kafka version 0.10.2.0). In particular i am using KafkaConsumer type. If the consumer stops and after a while it is restarted i would like to restart from the latest produced message, that is drop all the messages produced during the time the consumer was down. How can i achieve this?

谢谢

推荐答案

您将不会seekToEnd()到日志末尾.

请记住,您首先需要订阅一个主题,然后才能进行搜索.另外,订阅是懒惰的.因此,在搜索之前,您还需要添加虚拟民意测验".

Keep in mind, that you first need to subscribe to a topic before you can seek. Also, subscribing is lazy. Thus, you will need to add a "dummy poll" before you can seek, too.

consumer.subscribe(...)
consumer.poll() // dummy poll
consumer.seekToEnd()

// now enter your regular poll-loop

这篇关于使用者重启后,kafka-python从最后产生的消息中读取的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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