NoBrokersAvailable:NoBrokersAvailable-Kafka错误 [英] NoBrokersAvailable: NoBrokersAvailable-Kafka Error
问题描述
我已经开始学习Kafka.尝试对其进行基本操作.我坚持关于经纪人"的观点.
i have already started to learn Kafka. Trying basic operations on it. I have stucked on a point which about the 'Brokers'.
我的kafka正在运行,但是当我要创建分区时.
My kafka is running but when i want to create a partition.
from kafka import TopicPartition
(ERROR THERE) consumer = KafkaConsumer(bootstrap_servers='localhost:1234')
consumer.assign([TopicPartition('foobar', 2)])
msg = next(consumer)
回溯(最近一次通话最近): 文件",第1行,在 init 中的文件"/usr/local/lib/python2.7/dist-packages/kafka/consumer/group.py",第284行 self._client = KafkaClient(指标= self._metrics,** self.config) init 中的文件"/usr/local/lib/python2.7/dist-packages/kafka/client_async.py",第202行 self.config ['api_version'] = self.check_version(timeout = check_timeout) 文件"/usr/local/lib/python2.7/dist-packages/kafka/client_async.py",行791,在check_version中 引发Errors.NoBrokersAvailable() kafka.errors.NoBrokersAvailable:NoBrokersAvailable
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
推荐答案
您不能在使用者中创建分区.创建主题时会创建分区.例如,使用命令行工具:
You cannot create partitions within a consumer. Partitions are created when you create a topic. For example, using command line tool:
bin/kafka-topics.sh \
--zookeeper localhost:2181 \
--create --topic myNewTopic \
--partitions 10 \
--replication-factor 3
这将创建一个具有10个分区(从0到9编号)和复制因子3的新主题"myNewTopic".(请参阅 https://kafka.apache.org/documentation.html#quickstart_createtopic )
This creates a new topic "myNewTopic" with 10 partitions (numbered from 0 to 9) and replication factor 3. (see http://docs.confluent.io/3.0.0/kafka/post-deployment.html#admin-operations and https://kafka.apache.org/documentation.html#quickstart_createtopic)
在使用者中,如果调用assign()
,则表示您要消耗相应的分区,并且该分区必须已经存在.
Within your consumer, if you call assign()
, it means you want to consume the corresponding partition and this partition must exist already.
这篇关于NoBrokersAvailable:NoBrokersAvailable-Kafka错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!