Iintial setup, that contains only the MVP of the transfer-service
[demos/kafka/demos-kafka-payment-system-setup] / README.sh
1 #!/bin/bash
2
3 if [ "$1" = "cleanup" ]
4 then
5   docker-compose down
6   mvn clean
7   exit
8 fi
9
10 mvn package || exit 1
11 if [ ! -e transfer/target/BUILD ] || [ "$(find transfer/target/classes/ -anewer transfer/target/BUILD | grep transfer/target/classes/de )" != "" ]
12 then
13   echo "Rebuilding Docker-Image..."
14   docker-compose rm -svf transfer
15   mvn -f transfer/pom.xml docker:build
16   touch transfer/target/BUILD
17 fi
18 if [ "$1" = "build" ]; then exit; fi
19
20 docker-compose up -d zookeeper kafka
21
22 while ! [[ $(docker-compose run --rm kafka zookeeper-shell zookeeper:2181 ls /brokers/ids 2> /dev/null) =~ 1001 ]]; do echo "Waiting for kafka..."; sleep 1; done
23
24 docker-compose run --rm kafka kafka-topics --zookeeper zookeeper:2181 --if-not-exists --create --replication-factor 1 --partitions 5 --topic transfers
25
26 docker-compose up -d transfer
27
28 docker-compose run --name transferlog --rm kafka kafka-console-consumer --bootstrap-server kafka:9093 --topic transfers &
29 while ! [[ $(http 0:8091/actuator/health 2> /dev/null | jq -r .status ) =~ "UP" ]]; do echo "Waiting for transfer..."; sleep 1; done
30
31 echo '{"id":1,"payer":1,"payee":2, "amount":10}' | http -v :8091/transfers
32 http :8091/transfers/1
33 http -v  :8091/transfers id=2 payer=2 payee=1 amount=5
34 http :8091/transfers/2
35
36 docker container stop transferlog