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