I work on Windows and WSL2.
I installed on WSL2 a Kafka image in a Docker container. It works well : from WSL2 :
docker compose up
worksmytopic
with kafka-console-producer.sh
and kafka-console-consumer.sh
So this proves that it works from WSL2I used Intellij from Windows and I have kafka plugin. I would like to add a kafka broker with the following configuration. When I test connection there is a connection error because : BdtHostUnavailableException: URL "172.23.60.159:9092" is not available
I tried many solution without success :
Does anyone have a clue to help me?
hostname -I
eth0 : 172.23.60.159
docker : 172.17.0.1
docker-compose.yml
version: '3.3'
services:
kafka-collect:
image: apache/kafka:4.0.0
container_name: kafka-collect
ports:
- 9092:9092
environment:
KAFKA_NODE_ID: 1
KAFKA_PROCESS_ROLES: broker,controller
KAFKA_LISTENERS: PLAINTEXT://172.23.60.159:9092,CONTROLLER://localhost:9093
KAFKA_ADVERTISED_LISTENERS: PLAINTEXT://172.23.60.159:9092
KAFKA_CONTROLLER_LISTENER_NAMES: CONTROLLER
KAFKA_LISTENER_SECURITY_PROTOCOL_MAP: CONTROLLER:PLAINTEXT,PLAINTEXT:PLAINTEXT
KAFKA_CONTROLLER_QUORUM_VOTERS: 1@localhost:9093
KAFKA_OFFSETS_TOPIC_REPLICATION_FACTOR: 1
KAFKA_TRANSACTION_STATE_LOG_REPLICATION_FACTOR: 1
KAFKA_TRANSACTION_STATE_LOG_MIN_ISR: 1
KAFKA_GROUP_INITIAL_REBALANCE_DELAY_MS: 0
KAFKA_NUM_PARTITIONS: 3
CLUSTER_ID: MkU3OEVBNTcwNTJENDM2Qk
Change these:
KAFKA_LISTENERS: PLAINTEXT://0.0.0.0:9092,CONTROLLER://localhost:9093
KAFKA_ADVERTISED_LISTENERS: PLAINTEXT://kafka:9092
You can now connect to localhost:9092 or 127.0.0.1:9092 as bootstrap server in intellij.
As you are exposing the port 9092, you must point to localhost's mapped port, which is also 9092.
Not mandatory:
Assuming you're on Windows, add this line to the hosts file in C:\Windows\System32\drivers\etc\hosts (/etc/hosts in Linux)
127.0.0.1 kafka
Change the connection in Intellij so it points to kafka:9092 as bootstrap server.
Adding kafka as a host helps directing to the advertised listener defined in the server properties