Fehler in Setup eingebaut: Die Broker erreichen nicht all Zookeeper config/flawed-setup--zookeeper
authorKai Moritz <kai@juplo.de>
Sat, 28 Sep 2024 08:19:58 +0000 (10:19 +0200)
committerKai Moritz <kai@juplo.de>
Sat, 26 Oct 2024 17:43:36 +0000 (19:43 +0200)
README.sh
docker/docker-compose.yml

index da741d4..e38e8f0 100755 (executable)
--- 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
index b72f440..d1472ea 100644 (file)
@@ -1,18 +1,44 @@
 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
@@ -52,12 +78,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
@@ -72,7 +98,7 @@ services:
       - 9083:9083
     stop_grace_period: 120s
     depends_on:
-      - zookeeper
+      - zookeeper-3
 
   schema-registry:
     image: confluentinc/cp-schema-registry:7.7.1
@@ -145,7 +171,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: \
@@ -163,10 +189,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
@@ -189,9 +217,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: