From: Kai Moritz Date: Tue, 22 Jun 2021 16:37:30 +0000 (+0200) Subject: Setup with a scalable transfer-service (uses a consumer-group) X-Git-Url: http://juplo.de/gitweb/?a=commitdiff_plain;h=f968d08bd15d6643db1878b85089bbc17f2feaff;p=demos%2Fkafka%2Fdemos-kafka-payment-system-setup Setup with a scalable transfer-service (uses a consumer-group) --- diff --git a/README.sh b/README.sh index bc23ace..21ee7c8 100755 --- a/README.sh +++ b/README.sh @@ -11,7 +11,7 @@ mvn package || exit 1 if [ ! -e transfer/target/BUILD ] || [ "$(find transfer/target/classes/ -anewer transfer/target/BUILD | grep transfer/target/classes/de )" != "" ] then echo "Rebuilding Docker-Image..." - docker-compose rm -svf transfer + docker-compose rm -svf peter ute franz beate klaus mvn -f transfer/pom.xml docker:build touch transfer/target/BUILD fi @@ -23,20 +23,38 @@ while ! [[ $(docker-compose run --rm kafka zookeeper-shell zookeeper:2181 ls /br docker-compose run --rm kafka kafka-topics --zookeeper zookeeper:2181 --if-not-exists --create --replication-factor 1 --partitions 5 --topic transfers -docker-compose up -d transfer +docker-compose up -d peter ute franz beate klaus docker-compose run --name transferlog --rm kafka kafka-console-consumer --bootstrap-server kafka:9093 --topic transfers & -while ! [[ $(http 0:8091/actuator/health 2> /dev/null | jq -r .status ) =~ "UP" ]]; do echo "Waiting for transfer..."; sleep 1; done +while ! [[ $(http 0:8091/actuator/health 2> /dev/null | jq -r .status ) =~ "UP" ]]; do echo "Waiting for peter..."; sleep 1; done echo '{"id":1,"payer":1,"payee":2, "amount":10}' | http -v :8091/transfers -http :8091/transfers/1 +http --follow :8091/transfers/1 http -v :8091/transfers id=2 payer=2 payee=1 amount=5 -http :8091/transfers/2 - -docker-compose restart transfer -while ! [[ $(http 0:8091/actuator/health 2> /dev/null | jq -r .status ) =~ "UP" ]]; do echo "Waiting for transfer..."; sleep 1; done -http :8091/transfers/1 -http :8091/transfers/2 +http --follow :8091/transfers/2 +http -v :8091/transfers id=12 payer=2 payee=1 amount=5 +http -v :8091/transfers id=21 payer=2 payee=1 amount=5 +http -v :8091/transfers id=7 payer=2 payee=1 amount=5 +http -v :8091/transfers id=9 payer=2 payee=1 amount=5 +http -v :8091/transfers id=13 payer=2 payee=1 amount=5 +http -v :8091/transfers id=31 payer=2 payee=1 amount=5 +http -v --follow :8091/transfers/12 +http -v --follow :8091/transfers/21 +http -v --follow :8091/transfers/7 +http -v --follow :8091/transfers/9 +http -v --follow :8091/transfers/13 +http -v --follow :8091/transfers/31 + +docker-compose restart peter ute franz beate klaus +while ! [[ $(http 0:8091/actuator/health 2> /dev/null | jq -r .status ) =~ "UP" ]]; do echo "Waiting for peter..."; sleep 1; done +http -v --follow :8091/transfers/1 +http -v --follow :8091/transfers/2 +http -v --follow :8091/transfers/12 +http -v --follow :8091/transfers/21 +http -v --follow :8091/transfers/7 +http -v --follow :8091/transfers/9 +http -v --follow :8091/transfers/13 +http -v --follow :8091/transfers/31 docker container stop transferlog diff --git a/docker-compose.yml b/docker-compose.yml index 7629d23..1f7f5a4 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -3,7 +3,7 @@ services: zookeeper: image: confluentinc/cp-zookeeper:6.2.0 ports: - - "2181:2181" + - 2181:2181 environment: ZOOKEEPER_CLIENT_PORT: 2181 @@ -20,12 +20,92 @@ services: depends_on: - zookeeper - transfer: - image: juplo/payment-service-demo--transfer:1.1.0 + messages: + image: confluentinc/cp-kafka:6.2.0 + command: > + kafka-console-consumer + --bootstrap-server kafka:9093 + --from-beginning + --property print.key=true + --property key.separator=": " + --topic transfers + + peter: + image: juplo/payment-service-demo--transfer:2.0.0 + ports: + - 8091:8080 + environment: + juplo.transfer.bootstrap-servers: kafka:9093 + juplo.transfer.group-instance-id: peter + juplo.transfer.instance-id-uri-mapping.peter: http://localhost:8091 + juplo.transfer.instance-id-uri-mapping.ute: http://localhost:8092 + juplo.transfer.instance-id-uri-mapping.franz: http://localhost:8093 + juplo.transfer.instance-id-uri-mapping.beate: http://localhost:8094 + juplo.transfer.instance-id-uri-mapping.klaus: http://localhost:8095 + depends_on: + - zookeeper + - kafka + + ute: + image: juplo/payment-service-demo--transfer:2.0.0 + ports: + - 8092:8080 + environment: + juplo.transfer.bootstrap-servers: kafka:9093 + juplo.transfer.group-instance-id: ute + juplo.transfer.instance-id-uri-mapping.peter: http://localhost:8091 + juplo.transfer.instance-id-uri-mapping.ute: http://localhost:8092 + juplo.transfer.instance-id-uri-mapping.franz: http://localhost:8093 + juplo.transfer.instance-id-uri-mapping.beate: http://localhost:8094 + juplo.transfer.instance-id-uri-mapping.klaus: http://localhost:8095 + depends_on: + - zookeeper + - kafka + + franz: + image: juplo/payment-service-demo--transfer:2.0.0 + ports: + - 8093:8080 + environment: + juplo.transfer.bootstrap-servers: kafka:9093 + juplo.transfer.group-instance-id: franz + juplo.transfer.instance-id-uri-mapping.peter: http://localhost:8091 + juplo.transfer.instance-id-uri-mapping.ute: http://localhost:8092 + juplo.transfer.instance-id-uri-mapping.franz: http://localhost:8093 + juplo.transfer.instance-id-uri-mapping.beate: http://localhost:8094 + juplo.transfer.instance-id-uri-mapping.klaus: http://localhost:8095 + depends_on: + - zookeeper + - kafka + + beate: + image: juplo/payment-service-demo--transfer:2.0.0 + ports: + - 8094:8080 + environment: + juplo.transfer.bootstrap-servers: kafka:9093 + juplo.transfer.group-instance-id: beate + juplo.transfer.instance-id-uri-mapping.peter: http://localhost:8091 + juplo.transfer.instance-id-uri-mapping.ute: http://localhost:8092 + juplo.transfer.instance-id-uri-mapping.franz: http://localhost:8093 + juplo.transfer.instance-id-uri-mapping.beate: http://localhost:8094 + juplo.transfer.instance-id-uri-mapping.klaus: http://localhost:8095 + depends_on: + - zookeeper + - kafka + + klaus: + image: juplo/payment-service-demo--transfer:2.0.0 ports: - - "8091:8080" + - 8095:8080 environment: juplo.transfer.bootstrap-servers: kafka:9093 + juplo.transfer.group-instance-id: klaus + juplo.transfer.instance-id-uri-mapping.peter: http://localhost:8091 + juplo.transfer.instance-id-uri-mapping.ute: http://localhost:8092 + juplo.transfer.instance-id-uri-mapping.franz: http://localhost:8093 + juplo.transfer.instance-id-uri-mapping.beate: http://localhost:8094 + juplo.transfer.instance-id-uri-mapping.klaus: http://localhost:8095 depends_on: - zookeeper - kafka diff --git a/transfer b/transfer index 9001be5..5662a3f 160000 --- a/transfer +++ b/transfer @@ -1 +1 @@ -Subproject commit 9001be5d43ca1ca7a0dfe5f5a93c8903d1839f15 +Subproject commit 5662a3f4f6868e3ae474825e977e49bddddd4043