Kafka 读出指定 partition 指定位置数据


Q:Using kafka-python, is it possible to read a specific range of offsets for given partition(s)?
I looked through the documentation of the available consumers at http://kafka-python.readthedocs.org/en/1.0.0/apidoc/kafka.consumer.html but could not find anything that would let me do that.

 

A: How about:

consumer = KafkaConsumer()
partition = TopicPartition('foo', 0)
start = 1234
end = 2345
consumer.assign([partition])
consumer.seek(partition, start)
for msg in consumer:
    if msg.offset > end:
        break
    else:
        print msg

 

Reference:

https://github.com/dpkp/kafka-python/issues/648

 




					


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM