From: Kai Moritz Date: Sun, 11 Jun 2023 22:36:29 +0000 (+0200) Subject: Übung überarbeitet: Gegenüberstellung von Key-Hashing und Fixed X-Git-Tag: producer/rest-producer--headers---2023-06-signal~4 X-Git-Url: http://juplo.de/gitweb/?a=commitdiff_plain;h=eae5a26c61b3d0a767db1843d91671cd2beb4441;p=demos%2Fkafka%2Ftraining Übung überarbeitet: Gegenüberstellung von Key-Hashing und Fixed --- diff --git a/README.sh b/README.sh index 513a7d5..f227f47 100755 --- a/README.sh +++ b/README.sh @@ -30,41 +30,94 @@ 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 producer-0 producer-1 -while ! [[ $(http 0:8000/actuator/health 2> /dev/null) =~ "UP" ]]; do echo "Waiting for producer-0..."; sleep 1; done -while ! [[ $(http 0:8001/actuator/health 2> /dev/null) =~ "UP" ]]; do echo "Waiting for producer-1..."; sleep 1; done -docker-compose -f docker/docker-compose.yml up -d consumer +docker-compose -f docker/docker-compose.yml up -d producer +while ! [[ $(http 0:8080/actuator/health 2> /dev/null) =~ "UP" ]]; do echo "Waiting for producer..."; sleep 1; done -# tag::http[] -echo -n Nachricht 1 an Producer 0 | http -v :8000/foo -echo -n Nachricht 1 an Producer 1 | http -v :8001/foo -# end::http[] -echo -n Nachricht 2 an Producer 0 | http -v :8000/bar -echo -n Nachricht 2 an Producer 1 | http -v :8001/bar +# tag::hashed[] +echo -n Nachricht 1 an klaus über producer | http -v :8080/klaus +# end::hashed[] +echo -n Nachricht 2 an klaus über producer | http -v :8080/klaus +# tag::hashed[] +echo -n Nachricht 1 an peter über producer | http -v :8080/peter +# end::hashed[] +echo -n Nachricht 3 an klaus über producer | http -v :8080/klaus +echo -n Nachricht 2 an peter über producer | http -v :8080/peter +echo -n Nachricht 3 an peter über producer | http -v :8080/peter -docker-compose -f docker/docker-compose.yml logs consumer +echo Nachrichten in Partition 0: +kafkacat -b :9092 -t test -o 0 -p0 -f'key: %k\toffset: %o\tvalue: %s\n' -qe +echo +echo Nachrichten in Partition 1: +kafkacat -b :9092 -t test -o 0 -p1 -f'key: %k\toffset: %o\tvalue: %s\n' -qe +echo docker-compose -f docker/docker-compose.yml exec -T cli bash << 'EOF' -echo "Altering number of partitions from 3 to 7..." +echo "Altering number of partitions from 2 to 3..." kafka-topics --bootstrap-server kafka:9092 --describe --topic test # tag::repartitioning[] -kafka-topics --bootstrap-server kafka:9092 --alter --topic test --partitions 7 +kafka-topics --bootstrap-server kafka:9092 --alter --topic test --partitions 3 # end::repartitioning[] kafka-topics --bootstrap-server kafka:9092 --describe --topic test EOF -docker-compose -f docker/docker-compose.yml restart producer-0 producer-1 +docker-compose -f docker/docker-compose.yml restart producer +while ! [[ $(http 0:8080/actuator/health 2> /dev/null) =~ "UP" ]]; do echo "Waiting for producer..."; sleep 1; done + +echo -n Nachricht 4 an klaus über producer | http -v :8080/klaus +echo -n Nachricht 5 an peter über producer | http -v :8080/peter +echo -n Nachricht 4 an peter über producer | http -v :8080/peter +echo -n Nachricht 5 an klaus über producer | http -v :8080/klaus +echo -n Nachricht 6 an klaus über producer | http -v :8080/klaus +echo -n Nachricht 6 an peter über producer | http -v :8080/peter + +echo Nachrichten in Partition 0: +# tag::kafkacat[] +kafkacat -b :9092 -t test -o 0 -p0 -f'key: %k\toffset: %o\tvalue: %s\n' -qe +# end::kafkacat[] +echo +echo Nachrichten in Partition 1: +# tag::kafkacat[] +kafkacat -b :9092 -t test -o 0 -p1 -f'key: %k\toffset: %o\tvalue: %s\n' -qe +# end::kafkacat[] +echo +echo Nachrichten in Partition 2: +kafkacat -b :9092 -t test -o 0 -p2 -f'key: %k\toffset: %o\tvalue: %s\n' -qe + + +docker-compose -f docker/docker-compose.yml restart setup +sleep 1 +docker-compose -f docker/docker-compose.yml up -d producer-0 producer-1 while ! [[ $(http 0:8000/actuator/health 2> /dev/null) =~ "UP" ]]; do echo "Waiting for producer-0..."; sleep 1; done while ! [[ $(http 0:8001/actuator/health 2> /dev/null) =~ "UP" ]]; do echo "Waiting for producer-1..."; sleep 1; done -echo -n Nachricht 3 an Producer 0 | http -v :8000/foo -echo -n Nachricht 3 an Producer 1 | http -v :8001/foo -echo -n Nachricht 4 an Producer 0 | http -v :8000/bar -echo -n Nachricht 4 an Producer 1 | http -v :8001/bar +# tag::fixed[] +echo -n Nachricht 1 über producer-0 | http -v :8000/klaus +echo -n Nachricht 1 über producer-1 | http -v :8001/klaus +echo -n Nachricht 2 über producer-0 | http -v :8000/peter +echo -n Nachricht 2 über producer-1 | http -v :8001/peter +# end::fixed[] -docker-compose -f docker/docker-compose.yml logs consumer +docker-compose -f docker/docker-compose.yml exec -T cli bash << 'EOF' +echo "Altering number of partitions from 2 to 3..." +kafka-topics --bootstrap-server kafka:9092 --describe --topic test +kafka-topics --bootstrap-server kafka:9092 --alter --topic test --partitions 3 +kafka-topics --bootstrap-server kafka:9092 --describe --topic test +EOF -# tag::kafkacat[] -kafkacat -b :9092 -t test -o 0 -p0 -f'p=%p|o=%o|k=%k|v=%s\n' -qe -kafkacat -b :9092 -t test -o 0 -p1 -f'p=%p|o=%o|k=%k|v=%s\n' -qe -# end::kafkacat[] +docker-compose -f docker/docker-compose.yml restart producer-0 producer-1 +while ! [[ $(http 0:8000/actuator/health 2> /dev/null) =~ "UP" ]]; do echo "Waiting for producer-0..."; sleep 1; done +while ! [[ $(http 0:8001/actuator/health 2> /dev/null) =~ "UP" ]]; do echo "Waiting for producer-1..."; sleep 1; done + +echo -n Nachricht 3 über producer-0 | http -v :8000/klaus +echo -n Nachricht 3 über producer-1 | http -v :8001/klaus +echo -n Nachricht 4 über producer-0 | http -v :8000/peter +echo -n Nachricht 4 über producer-1 | http -v :8001/peter + +echo Nachrichten in Partition 0: +kafkacat -b :9092 -t test -o 0 -p0 -f'key: %k\toffset: %o\tvalue: %s\n' -qe +echo +echo Nachrichten in Partition 1: +kafkacat -b :9092 -t test -o 0 -p1 -f'key: %k\toffset: %o\tvalue: %s\n' -qe +echo +echo Nachrichten in Partition 2: +kafkacat -b :9092 -t test -o 0 -p2 -f'key: %k\toffset: %o\tvalue: %s\n' -qe diff --git a/docker/docker-compose.yml b/docker/docker-compose.yml index 0569a91..12ba802 100644 --- a/docker/docker-compose.yml +++ b/docker/docker-compose.yml @@ -131,6 +131,14 @@ services: producer.topic: test producer.partition: 1 - consumer: + consumer-1: image: juplo/simple-consumer:1.0-SNAPSHOT - command: kafka:9092 test my-group consumer + command: kafka:9092 test my-group consumer-1 + + consumer-2: + image: juplo/simple-consumer:1.0-SNAPSHOT + command: kafka:9092 test my-group consumer-2 + + consumer-3: + image: juplo/simple-consumer:1.0-SNAPSHOT + command: kafka:9092 test my-group consumer-3