这是编写简单的生产者/消费者的python代码:
import json import logging
from kafka import KafkaConsumer
consumer = KafkaConsumer('cassie',
bootstrap_servers=['localhost:9092'])
for message in consumer:
print("%s:%d:%d keys=%s" % (message.topic, message.partition,
message.offset, message.key,
message.value))
KafkaConsumer(auto_offset_reset='earlist', enable_auto_commit=false)
KafkaConsumer(value_deserializer=lambda m:
json.loads(m.decode('ascii')))
KafkaConsumer(consumer_timeout_ms=1000)
但是我有以下错误:
Traceback (most recent call last):
File "C:\Users\Qani\Desktop\Kafka-Python\simpleConsumer.py", line 6, in <module>
bootstrap_servers=['localhost:9092'])
File "C:\Python27\lib\site-packages\kafka\consumer\group.py", line 353, in __init__
self._client = KafkaClient(metrics=self._metrics, **self.config)
File "C:\Python27\lib\site-packages\kafka\client_async.py", line 239, in __init__
self.config['api_version'] = self.check_version(timeout=check_timeout)
File "C:\Python27\lib\site-packages\kafka\client_async.py", line 892, in check_version
raise Errors.NoBrokersAvailable()
NoBrokersAvailable: NoBrokersAvailable
有人可以帮助我解决这个问题吗?