Anzahl der Fehler für die Test-Logik verfügbar gemacht
[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
29
30 while ! [[ $(http 0:8081/actuator/health 2> /dev/null) =~ "UP" ]]; do echo "Waiting for consumer-1..."; sleep 1; done
31 while ! [[ $(http 0:8082/actuator/health 2> /dev/null) =~ "UP" ]]; do echo "Waiting for consumer-2..."; sleep 1; done
32 while ! [[ $(http 0:8083/actuator/health 2> /dev/null) =~ "UP" ]]; do echo "Waiting for consumer-3..."; sleep 1; done
33 while ! [[ $(http 0:8084/actuator/health 2> /dev/null) =~ "UP" ]]; do echo "Waiting for consumer-4..."; sleep 1; done
34 while ! [[ $(http 0:8085/actuator/health 2> /dev/null) =~ "UP" ]]; do echo "Waiting for consumer-5..."; sleep 1; done
35
36 sleep 5
37
38 docker-compose exec -T cli bash << 'EOF'
39 echo "Writing poison pill into topic test..."
40 # tag::poisonpill[]
41 echo 'BOOM!' | kafkacat -P -b kafka:9092 -t test
42 # end::poisonpill[]
43 EOF
44
45 while [[ $(http 0:8081/actuator/health 2> /dev/null) =~ "UP" ]]; do echo "consumer-1 is still running..."; sleep 1; done
46 while [[ $(http 0:8082/actuator/health 2> /dev/null) =~ "UP" ]]; do echo "consumer-2 is still running..."; sleep 1; done
47 while [[ $(http 0:8083/actuator/health 2> /dev/null) =~ "UP" ]]; do echo "consumer-3 is still running..."; sleep 1; done
48 while [[ $(http 0:8084/actuator/health 2> /dev/null) =~ "UP" ]]; do echo "consumer-4 is still running..."; sleep 1; done
49 while [[ $(http 0:8085/actuator/health 2> /dev/null) =~ "UP" ]]; do echo "consumer-5 is still running..."; sleep 1; done
50
51 http -v :8081/actuator/health
52 echo "Restarting consumer-1"
53 http -v post :8081/start
54
55 echo "Waiting for consumer-1 to come up"
56 while ! [[ $(http 0:8081/actuator/health 2> /dev/null) =~ "UP" ]]; do echo "Waiting for consumer-1..."; sleep 1; done
57 http -v :8081/actuator/health
58
59 echo "Waiting for consumer-1 to crash"
60 while [[ $(http 0:8081/actuator/health 2> /dev/null) =~ "UP" ]]; do echo "consumer-1 is still running..."; sleep 1; done
61 http -v :8081/actuator/health
62
63 docker-compose stop producer
64 docker-compose logs --tail=10 consumer-1
65 docker-compose logs --tail=10 consumer-2
66 docker-compose logs --tail=10 consumer-3
67 docker-compose logs --tail=10 consumer-4
68 docker-compose logs --tail=10 consumer-5