我正在尝试连接到远程kafka服务器,但无法传递simpleclient错误。Kafka服务器已经在运行,并且已经为我的设备创建了一个Kafka主题。在给Kafka写信之前,我需要设置其他的东西吗?
from kafka import SimpleProducer, SimpleClient
kafka = SimpleClient(hosts=["XX.XX.XXX.XXX:2181"]) # remote Ip:port
producer = SimpleProducer(kafka)
topic = "testTopic"
producer.send_messages(topic,"Test message")
错误如下:
Traceback (most recent call last):
File "C:/Users/..../kafkaProducer.py", line 6, in <module>
client = SimpleClient(hosts=["xxx:2181"])
File "C:\Python27\lib\site-packages\kafka\client.py", line 57, in __init__
self.load_metadata_for_topics() # bootstrap with all metadata
File "C:\Python27\lib\site-packages\kafka\client.py", line 531, in load_metadata_for_topics
resp = self.send_metadata_request(topics)
File "C:\Python27\lib\site-packages\kafka\client.py", line 596, in send_metadata_request
return self._send_broker_unaware_request(payloads, encoder, decoder)
File "C:\Python27\lib\site-packages\kafka\client.py", line 186, in _send_broker_unaware_request
raise KafkaUnavailableError('All servers failed to process request: %s' % hosts)
kafka.errors.KafkaUnavailableError: KafkaUnavailableError: All servers failed to process request: [('XX.XX.XX.162', 2181, 0)]
更新:kafka没有在服务器上运行,端口是9092。
from kafka import KafkaProducer
producer = KafkaProducer(bootstrap_servers=["XX.XX.XXX.XXX:9092"]) # remote Ip:port
topic = "testTopic"
producer.send(topic,"Test message")
暂无答案!
目前还没有任何答案,快来回答吧!