From 5dc2878a6828f240dc9a2e6de769febebc8f0de9 Mon Sep 17 00:00:00 2001 From: Kai Moritz Date: Wed, 14 Jun 2023 22:07:18 +0200 Subject: [PATCH] =?utf8?q?Setup=20und=20Bespiel-Skript=20f=C3=BCr=20die=20?= =?utf8?q?acks-=C3=9Cbung?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- README.sh | 81 +++++++++++++++++++++++++++++---------- docker/docker-compose.yml | 33 ++++++++++++++++ 2 files changed, 93 insertions(+), 21 deletions(-) diff --git a/README.sh b/README.sh index 4c99f7a..1462828 100755 --- a/README.sh +++ b/README.sh @@ -7,28 +7,67 @@ then fi docker-compose -f docker/docker-compose.yml up -d --remove-orphans kafka-1 kafka-2 kafka-3 -docker-compose -f docker/docker-compose.yml ps + echo "Waiting for the Kafka-Cluster to become ready..." docker-compose -f docker/docker-compose.yml run --rm cli cub kafka-ready -b kafka:9092 3 60 > /dev/null 2>&1 || exit 1 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 acks-0 acks-1 acks-all +while ! [[ $(http 0:8080/actuator/health 2> /dev/null) =~ "UP" ]]; do echo "Waiting for acks-0..."; sleep 1; done +while ! [[ $(http 0:8081/actuator/health 2> /dev/null) =~ "UP" ]]; do echo "Waiting for acks-1..."; sleep 1; done +while ! [[ $(http 0:8082/actuator/health 2> /dev/null) =~ "UP" ]]; do echo "Waiting for acks-all..."; sleep 1; done + +echo "Resetting the topic" +docker-compose -f docker/docker-compose.yml restart setup + +echo -n Alle Broker laufen über acks-0 | http -v :8080/foo +echo -n Alle Broker laufen über acks-1 | http -v :8081/foo +echo -n Alle Broker laufen über acks-all | http -v :8082/foo + +echo "Stopping kafka-1" +docker-compose -f docker/docker-compose.yml stop kafka-1 +echo "Restarting acks-0 acks-1 acks-all" +docker-compose -f docker/docker-compose.yml restart acks-0 acks-1 acks-all +while ! [[ $(http 0:8080/actuator/health 2> /dev/null) =~ "UP" ]]; do echo "Waiting for acks-0..."; sleep 1; done +while ! [[ $(http 0:8081/actuator/health 2> /dev/null) =~ "UP" ]]; do echo "Waiting for acks-1..."; sleep 1; done +while ! [[ $(http 0:8082/actuator/health 2> /dev/null) =~ "UP" ]]; do echo "Waiting for acks-all..."; sleep 1; done + +echo -n kafka-1 wurde beendet über acks-0 | http -v :8080/foo +echo -n kafka-1 wurde beendet über acks-1 | http -v :8081/foo +echo -n kafka-1 wurde beendet über acks-all | http -v :8082/foo + +echo "Stopping kafka-3" +docker-compose -f docker/docker-compose.yml stop kafka-3 +echo "Restarting acks-0 acks-1 acks-all" +docker-compose -f docker/docker-compose.yml restart acks-0 acks-1 acks-all +while ! [[ $(http 0:8080/actuator/health 2> /dev/null) =~ "UP" ]]; do echo "Waiting for acks-0..."; sleep 1; done +while ! [[ $(http 0:8081/actuator/health 2> /dev/null) =~ "UP" ]]; do echo "Waiting for acks-1..."; sleep 1; done +while ! [[ $(http 0:8082/actuator/health 2> /dev/null) =~ "UP" ]]; do echo "Waiting for acks-all..."; sleep 1; done + +echo -n kafka-1 und kafka-3 wurden beendet über acks-0 | http -v :8080/foo +echo -n kafka-1 und kafka-3 wurden beendet über acks-1 | http -v :8081/foo +echo -n kafka-1 und kafka-3 wurden beendet über acks-all | http -v :8082/foo + +# echo "Stopping kafka-2" +# docker-compose -f docker/docker-compose.yml stop kafka-2 +# echo "Restarting acks-0 acks-1 acks-all" +# docker-compose -f docker/docker-compose.yml restart acks-0 acks-1 acks-all +# while ! [[ $(http 0:8080/actuator/health 2> /dev/null) =~ "UP" ]]; do echo "Waiting for acks-0..."; sleep 1; done +# while ! [[ $(http 0:8081/actuator/health 2> /dev/null) =~ "UP" ]]; do echo "Waiting for acks-1..."; sleep 1; done +# while ! [[ $(http 0:8082/actuator/health 2> /dev/null) =~ "UP" ]]; do echo "Waiting for acks-all..."; sleep 1; done +# +# echo -n Alle Broker wurden beendet über acks-0 | http -v :8080/mit-acks-0 +# echo -n Alle Broker wurden beendet über acks-1 | http -v :8081/mit-acks-1 +# echo -n Alle Broker wurden beendet über acks-all | http -v :8082/mit-acks-all + +echo "Reading all messages, that were really written:" +kafkacat -b :9092 -t test -o 0 -f'key: %k\toffset: %o\tvalue: %s\n' -qe + +# echo "Restarting all brokers" +# docker-compose -f docker/docker-compose.yml up -d kafka-1 kafka-2 kafka-3 +# echo "Waiting for the Kafka-Cluster to become ready..." +# docker-compose -f docker/docker-compose.yml run --rm cli cub kafka-ready -b kafka:9092 3 60 > /dev/null 2>&1 || exit 1 +# sleep 1 +# echo "Reading all messages, that were really written eventually:" +# kafkacat -b :9092 -t test -o 0 -f'key: %k\toffset: %o\tvalue: %s\n' -qe diff --git a/docker/docker-compose.yml b/docker/docker-compose.yml index 3a99d56..03935df 100644 --- a/docker/docker-compose.yml +++ b/docker/docker-compose.yml @@ -98,3 +98,36 @@ services: command: sleep infinity depends_on: - setup + + acks-0: + image: juplo/rest-producer:1.0-SNAPSHOT + ports: + - 8080:8080 + environment: + server.port: 8080 + producer.bootstrap-server: kafka:9092 + producer.client-id: acks-0 + producer.acks: 0 + producer.topic: test + + acks-1: + image: juplo/rest-producer:1.0-SNAPSHOT + ports: + - 8081:8080 + environment: + server.port: 8080 + producer.bootstrap-server: kafka:9092 + producer.client-id: acks-1 + producer.acks: 1 + producer.topic: test + + acks-all: + image: juplo/rest-producer:1.0-SNAPSHOT + ports: + - 8082:8080 + environment: + server.port: 8080 + producer.bootstrap-server: kafka:9092 + producer.client-id: acks-all + producer.acks: all + producer.topic: test -- 2.20.1