From: Kai Moritz Date: Sat, 28 Sep 2024 08:19:58 +0000 (+0200) Subject: Fehler in Setup eingebaut: Die Broker erreichen nicht all Zookeeper X-Git-Tag: config/flawed-setup--zookeeper--REBASE-ANFANG X-Git-Url: http://juplo.de/gitweb/?a=commitdiff_plain;h=06ab23dcff0acd22a5f558838c15696da64ca742;p=demos%2Fkafka%2Ftraining Fehler in Setup eingebaut: Die Broker erreichen nicht all Zookeeper --- diff --git a/README.sh b/README.sh index da741d4..e38e8f0 100755 --- a/README.sh +++ b/README.sh @@ -13,20 +13,14 @@ docker compose -f docker/docker-compose.yml up -t0 -d cli sleep 1 docker compose -f docker/docker-compose.yml logs setup -echo -echo "Hilfe-Ausgabe von kafkacat" -echo -docker compose -f docker/docker-compose.yml exec -T cli kafkacat -h -echo -echo "Nachrichten schreiben mit kafkacat" -echo -docker compose -f docker/docker-compose.yml exec -T cli kafkacat -P -b kafka:9092 -t test << EOF -Hallo Welt! -Nachricht #1 -Nachricht #2 -Nachricht #3 -EOF -echo -echo "Nachrichten lesen mit kafkacat" -echo -docker compose -f docker/docker-compose.yml exec cli kafkacat -C -b kafka:9092 -t test -o beginning -e +docker compose -f docker/docker-compose.yml up -d producer +docker compose -f docker/docker-compose.yml up -d consumer + +sleep 5 +docker compose -f docker/docker-compose.yml stop consumer + +docker compose -f docker/docker-compose.yml start consumer +sleep 5 + +docker compose -f docker/docker-compose.yml stop producer consumer +docker compose -f docker/docker-compose.yml logs consumer diff --git a/docker/docker-compose.yml b/docker/docker-compose.yml index 3aa7920..2b579dd 100644 --- a/docker/docker-compose.yml +++ b/docker/docker-compose.yml @@ -1,19 +1,45 @@ version: '3.2' services: - zookeeper: + zookeeper-1: image: confluentinc/cp-zookeeper:7.7.1 environment: + ZOOKEEPER_SERVER_ID: 1 ZOOKEEPER_CLIENT_PORT: 2181 + ZOOKEEPER_SERVERS: zookeeper-1:2888:3888;zookeeper-2:2888:3888;zookeeper-3:2888:3888 ports: - 2181:2181 volumes: - - zookeeper-data:/var/lib/zookeeper/data - - zookeeper-log:/var/lib/zookeeper/log + - zookeeper-1-data:/var/lib/zookeeper/data + - zookeeper-1-log:/var/lib/zookeeper/log + + zookeeper-2: + image: confluentinc/cp-zookeeper:7.7.1 + environment: + ZOOKEEPER_SERVER_ID: 2 + ZOOKEEPER_CLIENT_PORT: 2181 + ZOOKEEPER_SERVERS: zookeeper-1:2888:3888;zookeeper-2:2888:3888;zookeeper-3:2888:3888 + ports: + - 2182:2181 + volumes: + - zookeeper-2-data:/var/lib/zookeeper/data + - zookeeper-2-log:/var/lib/zookeeper/log + + zookeeper-3: + image: confluentinc/cp-zookeeper:7.7.1 + environment: + ZOOKEEPER_SERVER_ID: 3 + ZOOKEEPER_CLIENT_PORT: 2181 + ZOOKEEPER_SERVERS: zookeeper-1:2888:3888;zookeeper-2:2888:3888;zookeeper-3:2888:3888 + ports: + - 2183:2181 + volumes: + - zookeeper-3-data:/var/lib/zookeeper/data + - zookeeper-3-log:/var/lib/zookeeper/log kafka-1: image: confluentinc/cp-kafka:7.7.1 environment: - KAFKA_ZOOKEEPER_CONNECT: zookeeper:2181 + KAFKA_ZOOKEEPER_CONNECT: zookeeper-1:2181 KAFKA_LISTENERS: BROKER://:9092, LOCALHOST://:9081 KAFKA_LISTENER_SECURITY_PROTOCOL_MAP: BROKER:PLAINTEXT, LOCALHOST:PLAINTEXT KAFKA_ADVERTISED_LISTENERS: BROKER://kafka-1:9092, LOCALHOST://localhost:9081 @@ -27,12 +53,12 @@ services: - 9081:9081 stop_grace_period: 120s depends_on: - - zookeeper + - zookeeper-1 kafka-2: image: confluentinc/cp-kafka:7.7.1 environment: - KAFKA_ZOOKEEPER_CONNECT: zookeeper:2181 + KAFKA_ZOOKEEPER_CONNECT: zookeeper-2:2181 KAFKA_LISTENERS: BROKER://:9092, LOCALHOST://:9082 KAFKA_LISTENER_SECURITY_PROTOCOL_MAP: BROKER:PLAINTEXT, LOCALHOST:PLAINTEXT KAFKA_ADVERTISED_LISTENERS: BROKER://kafka-2:9092, LOCALHOST://localhost:9082 @@ -51,12 +77,12 @@ services: - kafka stop_grace_period: 120s depends_on: - - zookeeper + - zookeeper-2 kafka-3: image: confluentinc/cp-kafka:7.7.1 environment: - KAFKA_ZOOKEEPER_CONNECT: zookeeper:2181 + KAFKA_ZOOKEEPER_CONNECT: zookeeper-3:2181 KAFKA_LISTENERS: BROKER://:9092, LOCALHOST://:9083 KAFKA_LISTENER_SECURITY_PROTOCOL_MAP: BROKER:PLAINTEXT, LOCALHOST:PLAINTEXT KAFKA_ADVERTISED_LISTENERS: BROKER://kafka-3:9092, LOCALHOST://localhost:9083 @@ -70,7 +96,7 @@ services: - 9083:9083 stop_grace_period: 120s depends_on: - - zookeeper + - zookeeper-3 schema-registry: image: confluentinc/cp-schema-registry:7.7.1 @@ -143,7 +169,7 @@ services: kafka-topics --bootstrap-server kafka:9092 \ --create \ --topic test \ - --partitions 2 \ + --partitions 1 \ --replication-factor 3 \ --config min.insync.replicas=2 \ && echo Das Topic \'test\' wurde erfolgreich angelegt: \ @@ -161,10 +187,12 @@ services: environment: HTTP_PORT: 80 CONNECTION_JUPLO_NAME: juplo - CONNECTION_JUPLO_CONN: zookeeper:2181 + CONNECTION_JUPLO_CONN: zookeeper-1:2181 AUTO_CONNECT_CONNECTION_ID: JUPLO depends_on: - - zookeeper + - zookeeper-1 + - zookeeper-2 + - zookeeper-3 akhq: image: tchiotludo/akhq:0.23.0 @@ -187,9 +215,21 @@ services: - kafka-2 - kafka-3 + producer: + image: juplo/simple-producer:1.0-SNAPSHOT + command: kafka:9092 test producer + + consumer: + image: juplo/simple-consumer:1.0-SNAPSHOT + command: kafka:9092 test my-group consumer + volumes: - zookeeper-data: - zookeeper-log: + zookeeper-1-data: + zookeeper-1-log: + zookeeper-2-data: + zookeeper-2-log: + zookeeper-3-data: + zookeeper-3-log: kafka-1-data: kafka-2-data: kafka-3-data: