简体   繁体   中英

Python Kafka client cannot connect to remote Kafka server

I have an Ubuntu VM on cloud, where I downloaded Kafka version 2.8.1 from the Official Kafka site and followed the instructions in Kafka's official quickstart guide .

I am using a python client to consume one of the topics that I created as part of the quickstart guide. When I run it on the VM, everything runs fine, however, when I run the same program on my local system, I get the below error

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

The python program I am using:

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())

I have ensured that the necessary ports (9022) on Ubuntu is open - I checked that I could te.net into port 9022 from my local system.

I am not sure what could be the reason that I am unable to access Kafka over inte.net. Am I missing something obvious?

Change the following attribute in config/server.properties to bootstrap server address you are using in your code.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM