Healthcheck und Depends-On für die KRAFT-Konfig
authorKai Moritz <kai@juplo.de>
Wed, 26 Oct 2022 16:44:00 +0000 (18:44 +0200)
committerKai Moritz <kai@juplo.de>
Tue, 1 Nov 2022 10:06:14 +0000 (11:06 +0100)
docker-compose.yml

index 293db15..024b4d8 100644 (file)
@@ -34,6 +34,8 @@ services:
       KAFKA_CFG_AUTO_CREATE_TOPICS_ENABLE: "false"
     ports:
       - 9081:9081
+    healthcheck:
+      test: [ "CMD", "kafka-topics.sh", "--bootstrap-server", ":9092", "--list" ]
 
   kafka-2:
     image: bitnami/kafka:3.3.1
@@ -58,6 +60,8 @@ services:
       default:
         aliases:
           - kafka
+    healthcheck:
+      test: [ "CMD", "kafka-topics.sh", "--bootstrap-server", ":9092", "--list" ]
 
   kafka-3:
     image: bitnami/kafka:3.3.1
@@ -77,6 +81,8 @@ services:
       KAFKA_CFG_AUTO_CREATE_TOPICS_ENABLE: "false"
     ports:
       - 9083:9083
+    healthcheck:
+      test: [ "CMD", "kafka-topics.sh", "--bootstrap-server", ":9092", "--list" ]
 
   setup:
     image: juplo/toolbox
@@ -86,6 +92,13 @@ services:
         kafka-topics --bootstrap-server kafka:9092 --create --topic test --partitions 2 --replication-factor 3 --config min.insync.replicas=2
         kafka-topics --bootstrap-server kafka:9092 --describe --topic test
       "
+    depends_on:
+      kafka-1:
+        condition: service_healthy
+      kafka-2:
+        condition: service_healthy
+      kafka-3:
+        condition: service_healthy
 
   cli:
     image: juplo/toolbox
@@ -94,18 +107,46 @@ services:
   producer:
     image: juplo/simple-producer:1.0-SNAPSHOT
     command: producer
+    depends_on:
+      kafka-1:
+        condition: service_healthy
+      kafka-2:
+        condition: service_healthy
+      kafka-3:
+        condition: service_healthy
 
   consumer-1:
     image: juplo/simple-consumer:1.0-SNAPSHOT
     command: kafka:9092 test my-group consumer-1
+    depends_on:
+      kafka-1:
+        condition: service_healthy
+      kafka-2:
+        condition: service_healthy
+      kafka-3:
+        condition: service_healthy
 
   consumer-2:
     image: juplo/simple-consumer:1.0-SNAPSHOT
     command: kafka:9092 test my-group consumer-2
+    depends_on:
+      kafka-1:
+        condition: service_healthy
+      kafka-2:
+        condition: service_healthy
+      kafka-3:
+        condition: service_healthy
 
   consumer-3:
     image: juplo/simple-consumer:1.0-SNAPSHOT
     command: kafka:9092 test my-group consumer-3
+    depends_on:
+      kafka-1:
+        condition: service_healthy
+      kafka-2:
+        condition: service_healthy
+      kafka-3:
+        condition: service_healthy
 
   spikzettel:
     image: juplo/toolbox
@@ -116,3 +157,10 @@ services:
           --topic __consumer_offsets --from-beginning \
           --formatter "kafka.coordinator.group.GroupMetadataManager\$$OffsetsMessageFormatter"
       '
+    depends_on:
+      kafka-1:
+        condition: service_healthy
+      kafka-2:
+        condition: service_healthy
+      kafka-3:
+        condition: service_healthy