Issue
I have a question about some code in python that uses the kafka-python module and I really don't know why it doesn't work. After I initialize the Zookeeper&Kafka server with like the quickstart page suggests and creating at topic at my computer, I try to run the following code on my smartphone, using Termux:
from json import dumps, loads
from kafka import KafkaProducer, KafkaConsumer
class CommunicationLayer:
def __init__(self, node_id):
self.output_publisher = KafkaProducer(bootstrap_servers=['192.168.1.103:9092'], value_serializer=lambda x:
dumps(x).encode('utf-8'))
self.window_receiver = KafkaConsumer("node_{}".format(node_id), bootstrap_servers=['192.168.1.103:9092'] , value_deserializer=lambda x: loads(x.decode('utf-8')))
...
(code that doesn't really help)
...
(The IP points to the machine that runs the kafka server). As soon as I run this code, I get NoBrokerAvailable error which, as far as I know, comes up only when you haven't initialized the servers. Do I miss something?
Solution
I try to run the following code on my smartphone
Note: Kafka clients aren't intended to be ran in such environments where network connection is unreliable.
The IP points to the machine that runs the kafka server
Is ZooKeeper as well as Kafka exposed externally on this machine and not only listening locally?
Similarly, you need to set the advertised.listeners
property in Kafka properties to be this external address for any clients to be able to actually connect after the bootstrap connection.
Answered By - OneCricketeer