gpt4 book ai didi

python - NoBrokersAvailable : NoBrokersAvailable-Kafka Error

转载 作者:太空宇宙 更新时间:2023-11-03 12:56:44 47 4
gpt4 key购买 nike

我已经开始学习Kafka了。尝试对其进行基本操作。我一直坚持关于“经纪人”的观点。

我的 kafka 正在运行,但是当我想创建一个分区时。

 from kafka import TopicPartition
(ERROR THERE) consumer = KafkaConsumer(bootstrap_servers='localhost:1234')
consumer.assign([TopicPartition('foobar', 2)])
msg = next(consumer)

traceback (most recent call last): File "", line 1, in File "/usr/local/lib/python2.7/dist-packages/kafka/consumer/group.py", line 284, in init self._client = KafkaClient(metrics=self._metrics, **self.config) File "/usr/local/lib/python2.7/dist-packages/kafka/client_async.py", line 202, in init self.config['api_version'] = self.check_version(timeout=check_timeout) File "/usr/local/lib/python2.7/dist-packages/kafka/client_async.py", line 791, in check_version raise Errors.NoBrokersAvailable() kafka.errors.NoBrokersAvailable: NoBrokersAvailable

最佳答案

我在kafka streaming的时候出现了同样的错误。下面的代码解决了我的错误:我们需要在 KafkaProducer 中定义 API 版本。

KafkaProducer(bootstrap_servers=['localhost:9092'],
api_version=(0,11,5),
value_serializer=lambda x: dumps(x).encode('utf-8'))

关于python - NoBrokersAvailable : NoBrokersAvailable-Kafka Error,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38854957/

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