I'd like to extend the same question Spring Boot Kafka Startup error "Connection to node -1 could not be established. Broker may not be available." here.
I install docker desktop on my windows 10 Pro machine and using below file Kafka is installed.
I used below file
version: "3.7"
networks:
kafka-net:
name: kafka-net
driver: bridge
services:
zookeeper:
image: zookeeper:3.7.0
container_name: zookeeper
restart: always
networks:
- kafka-net
ports:
- "2181:2181"
volumes:
- C:/development/kafka/docker-data/zookeeper:/bitnami/zookeeper
kafka:
image: wurstmeister/kafka:2.13-2.7.0
container_name: kafka
restart: always
networks:
- kafka-net
ports:
- "9092:9092"
volumes:
- C:/development/kafka/docker-data/kafka:/bitnami/kafka
environment:
KAFKA_LISTENER_SECURITY_PROTOCOL_MAP: DOCKER_INTERNAL:PLAINTEXT,DOCKER_EXTERNAL:PLAINTEXT
KAFKA_LISTENERS: DOCKER_INTERNAL://:29092,DOCKER_EXTERNAL://:9092
KAFKA_ADVERTISED_LISTENERS: DOCKER_INTERNAL://kafka:29092,DOCKER_EXTERNAL://${DOCKER_HOST_IP:-127.0.0.1}:9092
KAFKA_INTER_BROKER_LISTENER_NAME: DOCKER_INTERNAL
KAFKA_ZOOKEEPER_CONNECT: "zookeeper:2181"
KAFKA_BROKER_ID: 1
KAFKA_OFFSETS_TOPIC_REPLICATION_FACTOR: 1
depends_on:
- zookeeper
and this has created
C:\>docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
7ea5afc30df0 wurstmeister/kafka:2.13-2.7.0 "start-kafka.sh" 27 minutes ago Up 27 minutes 0.0.0.0:9092->9092/tcp kafka
dd0244a8c978 zookeeper:3.7.0 "/docker-entrypoint.…" 27 minutes ago Up 27 minutes 2888/tcp, 3888/tcp, 0.0.0.0:2181->2181/tcp, 8080/tcp zookeeper
Below is the process
bash-5.1# kafka-topics.sh --bootstrap-server localhost:9092 --create --topic t_hello --partitions 1 --replication-factor 1
WARNING: Due to limitations in metric names, topics with a period ('.') or underscore ('_') could collide. To avoid issues it is best to use either, but not both.
Created topic t_hello.
bash-5.1#
bash-5.1#
bash-5.1# kafka-topics.sh --bootstrap-server localhost:9092 --list
t_hello
But when I am running producer or consumer I am getting below error.
[Producer clientId=producer-1] Bootstrap broker localhost:9092 (id: -1 rack: null) disconnected