'Running Kafka Confluent Platform on WSL 2 (Ubuntu Distribution) and Spring application on Windows (Broker may not be available)
I'm running Confluent Platform in wsl 2(Ubuntu Distribution) and I also running a Spring application on Windows but when I send a message with a producer I have this error:
Connection to node -1 (localhost/127.0.0.1:9092) could not be established. Broker may not be available. Bootstrap broker localhost:9092 (id: -1 rack: null) disconnected
I have a look this articles: https://www.confluent.io/blog/kafka-client-cannot-connect-to-broker-on-aws-on-docker-etc/ and https://forum.confluent.io/t/running-kafka-connect-sink-on-separate-machine-from-zookeeper-topic-non-localhost/3038 and https://www.confluent.io/blog/kafka-listeners-explained/
But I don't find the solution.
What is the configuration in concluent/etc/kafka/server.properties file?
I've set this:
advertised.listeners=PLAINTEXT://127.0.0.1:9092
listener.security.protocol.map=PLAINTEXT:PLAINTEXT
listeners=PLAINTEXT://0.0.0.0:9092
Kafka is running on: "localhost:9092" and within WSL2 I can send and read messages correctly but it doesn't work my spring boot application on Windows.
I see this answer, but It doesn't work in my localhost: running Kafka on WSL and make producer on windows
Do I have to change something in my Windows configuration? In C:\Windows\System32\drivers\etc\hosts?
Could you please advice how to solve this error? Thanks in advance!
Solution 1:[1]
You need to use ifconfig (or ip addr) inside WSL2 terminal, find its external interface IP, then use that as the advertised listener.
Then you'll need to use netsh interface portproxy command from Windows CMD to forward ports from the hypervisor to the host. This also assumes listeners=PLAINTEXT://0.0.0.0:9092
Example
netsh interface portproxy add v4tov4 listenport=9092 listenaddress=0.0.0.0 connectport=9092 connectaddress=XXX.XX.XX.XX
Then connecting to localhost from CMD will forward requests to the hypervisor, which will return its advertised listener address.
You could also try using the IP of the hypervisor directly, rather than localhost / port forwarding
Or you can just use Docker for Windows, run Kafka and configure listeners there, and it'll forward ports correctly on its own
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 |
