Python Kafka客户端无法连接到远程Kafka服务器



我在云端有一个Ubuntu虚拟机,我从Kafka官方网站下载了Kafka 2.8.1版本,并按照Kafka官方快速入门指南中的说明进行操作。

我正在使用一个python客户端来使用我在快速入门指南中创建的一个主题。当我在VM上运行它时,一切都运行正常,然而,当我在本地系统上运行相同的程序时,我得到以下错误

Unable connect to node with id 0: [Errno 8] nodename nor servname provided, or not known
Traceback (most recent call last):
...
...
File "/Path/python3.9/site-packages/aiokafka/client.py", line 547, in check_version
raise KafkaConnectionError(
kafka.errors.KafkaConnectionError: KafkaConnectionError: No connection to node with id 0

我正在使用的python程序:

import asyncio
import aiokafka
async def consume(self):
consumer = aiokafka.AIOKafkaConsumer(
"quickstart-events", bootstrap_servers="IP:9092"
)
try:
await consumer.start()
async for msg in self.consumer:
print(
"consumed: ",
msg.topic,
msg.partition,
msg.offset,
msg.key,
msg.value,
msg.timestamp,
)
finally:
await consumer.stop()
asyncio.run(consume())

我已经确保Ubuntu上必要的端口(9022)是开放的我检查了我可以从本地系统telnet到9022端口。

我不确定是什么原因导致我无法通过互联网访问Kafka。我错过了什么明显的东西吗?

config/server.properties中的以下属性更改为您在代码中使用的引导服务器地址

advertised.listeners = PLAINTEXT://IP or FQDN:9092

最新更新