From: Kai Moritz Date: Wed, 1 Nov 2023 12:27:10 +0000 (+0100) Subject: `acks`-Übung auf das Setup aus `grundlagen/docker` umgestellt X-Git-Url: http://juplo.de/gitweb/?a=commitdiff_plain;h=6a274edfde292393fbc7d2b9bf2cb4b0aafe58c2;p=demos%2Fkafka%2Ftraining `acks`-Übung auf das Setup aus `grundlagen/docker` umgestellt --- diff --git a/README.sh b/README.sh index 7d6406d..45a4ba6 100755 --- a/README.sh +++ b/README.sh @@ -6,27 +6,65 @@ then exit 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 up --remove-orphans setup || exit 1 -docker-compose -f docker/docker-compose.yml ps -docker-compose -f docker/docker-compose.yml up -t0 -d cli -sleep 1 -docker-compose -f docker/docker-compose.yml logs setup +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 + +docker-compose -f docker/docker-compose.yml exec -T cli bash << 'EOF' +# tag::describe[] +kafka-topics --bootstrap-server kafka:9092 --describe --topic test +# end::describe[] +EOF + +# tag::foo[] +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 +# end::foo[] echo -echo "Hilfe-Ausgabe von kafkacat" -echo -docker-compose -f docker/docker-compose.yml exec -T cli kafkacat -h +echo "Reading all messages, that were really written:" +# tag::foo[] +kafkacat -b :9092 -t test -o 0 -f'key: %k\toffset: %o\tvalue: %s\n' -qe +# end::foo[] + +echo "Stopping kafka-1" +docker-compose -f docker/docker-compose.yml stop kafka-1 +docker-compose -f docker/docker-compose.yml exec cli kafka-topics --bootstrap-server kafka:9092 --describe --topic test echo -echo "Nachrichten schreiben mit kafkacat" +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 -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 "Reading all messages, that were really written:" +kafkacat -b :9092 -t test -o 0 -f'key: %k\toffset: %o\tvalue: %s\n' -qe + +echo "Stopping kafka-3" +docker-compose -f docker/docker-compose.yml stop kafka-3 +docker-compose -f docker/docker-compose.yml exec cli kafka-topics --bootstrap-server kafka:9092 --describe --topic test echo -echo "Nachrichten lesen mit kafkacat" +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 -docker-compose -f docker/docker-compose.yml exec cli kafkacat -C -b kafka:9092 -t test -o beginning -e +echo "Reading all messages, that were really written:" +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 dd7c830..c06de62 100644 --- a/docker/docker-compose.yml +++ b/docker/docker-compose.yml @@ -187,6 +187,39 @@ services: - kafka-2 - kafka-3 + 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 + volumes: zookeeper-data: zookeeper-log: