Compose-Setup und README.sh für dieses Beispiel repariert
[demos/kafka/training] / README.sh
1 #!/bin/bash
2
3 IMAGE=juplo/endless-consumer:1.0-SNAPSHOT
4
5 if [ "$1" = "cleanup" ]
6 then
7   docker-compose down -v
8   mvn clean
9   exit
10 fi
11
12 docker-compose up -d zookeeper kafka cli
13
14 if [[
15   $(docker image ls -q $IMAGE) == "" ||
16   "$1" = "build"
17 ]]
18 then
19   mvn install || exit
20 else
21   echo "Using image existing images:"
22   docker image ls $IMAGE
23 fi
24
25 echo "Waiting for the Kafka-Cluster to become ready..."
26 docker-compose exec cli cub kafka-ready -b kafka:9092 1 60 > /dev/null 2>&1 || exit 1
27 docker-compose up setup
28 docker-compose up -d producer
29 docker-compose up consumer &
30 while ! [[ $(http 0:8081/actuator/health 2> /dev/null) =~ "UP" ]]; do echo "Waiting for consumer..."; sleep 1; done
31 sleep 5
32 docker-compose exec -T cli bash << 'EOF'
33 echo "Writing poison pill into topic test..."
34 # tag::poisonpill[]
35 echo 'BOOM!' | kafkacat -P -b kafka:9092 -t test
36 # end::poisonpill[]
37 EOF
38 while [[ $(http 0:8081/actuator/health 2> /dev/null) =~ "UP" ]]; do echo "Consumer is still running..."; sleep 1; done
39 http -v :8081/actuator/health
40 echo "Restarting consumer"
41 http -v post :8081/start
42 while ! [[ $(http 0:8081/actuator/health 2> /dev/null) =~ "UP" ]]; do echo "Waiting for consumer..."; sleep 1; done
43 while [[ $(http 0:8081/actuator/health 2> /dev/null) =~ "UP" ]]; do echo "Consumer is still running..."; sleep 1; done
44 http -v :8081/actuator/health
45 http -v post :8081/actuator/shutdown
46 docker-compose stop producer