If you are encountering the error "connection to node -1 (localhost/127.0.0.1:9092) could not be established. broker may not be available." in your Kafka setup, here are some steps to resolve it:
./bin/kafka-server-start.sh config/server.properties
advertised.listeners=PLAINTEXT://your-broker-hostname:9092
./bin/kafka-server-stop.sh
./bin/zookeeper-server-stop.sh
./bin/zookeeper-server-start.sh config/zookeeper.properties
./bin/kafka-server-start.sh config/server.properties
If the issue persists after trying these steps, consider checking Kafka logs for more detailed error messages that might provide insights into the problem.
To obtain the external interface IP on Ubuntu terminal, you can use the command:
ip addr | grep eth0
Once you have the IP, set it as the advertised.listener. Then, on Windows cmd, execute the following command to forward ports:
netsh interface portproxy add v4tov4 listenport=9092 listenaddress=0.0.0.0 connectport=9092 connectaddress=XXX.XX.XX.XX
Replace XXX.XX.XX.XX with the external interface IP. After executing this command, you can verify the setup using:
netstat -ab
This will display the IP and Port TCP as 0.0.0.0:9092, confirming that the port forwarding is functioning correctly.
I encountered a similar issue where everything appeared to be functioning correctly, yet an error persisted. Upon reviewing my changes related to the Kafka initial setup, I identified the following steps to resolve the issue:
#listeners=PLAINTEXT://:9092
listeners=PLAINTEXT://127.0.0.1:9092
listeners=PLAINTEXT://localhost:9092