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!
CodePudding user response:
You need to use ifconfig
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.
Or you can just use Docker for Windows, run Kafka and configure listeners there, and it'll forward ports correctly on its own