gpt4 book ai didi

apache-kafka - 断言错误 : Unassigned partition

转载 作者:行者123 更新时间:2023-12-05 03:11:41 33 4
gpt4 key购买 nike

我试图通过设置偏移量来使用主题中的数据,但出现断言错误 -

from kafka import KafkaConsumer

consumer = KafkaConsumer('foobar1',
bootstrap_servers=['localhost:9092'])
print 'process started'
print consumer.partitions_for_topic('foobar1')
print 'done'
consumer.seek(0,10)

for message in consumer:
print ("%s:%d:%d: key=%s value=%s" % (message.topic, message.partition,
message.offset, message.key,
message.value))
print 'process ended'

错误:-

Traceback (most recent call last):
File "/Users/pn/Documents/jobs/ccdn/kafka_consumer_1.py", line 21, in <module>
consumer.seek(0,10)
File "/Users/pn/.virtualenvs/vpsq/lib/python2.7/site-packages/kafka/consumer/group.py", line 549, in seek
assert partition in self._subscription.assigned_partitions(), 'Unassigned partition'
AssertionError: Unassigned partition

最佳答案

下面是一个解决问题的例子:

from kafka import KafkaConsumer, TopicPartition

con = KafkaConsumer(bootstrap_servers = my_bootstrapservers)
tp = TopicPartition(my_topic, 0)
con.assign([tp])
con.seek_to_beginning()
con.seek(tp, 1000000)

引用: kafka consumer seek is not working: AssertionError: Unassigned partition

关于apache-kafka - 断言错误 : Unassigned partition,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36381328/

33 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com