From ea17bf7b7dcdc3dda7c951439a3ae6e15b97477f Mon Sep 17 00:00:00 2001 From: Kai Moritz Date: Sun, 11 Jun 2023 17:12:15 +0200 Subject: [PATCH] =?utf8?q?=C3=9Cbung=20an=20die=20Docker-=C3=9Cbung=20ange?= =?utf8?q?passt?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- README.sh | 12 ++++++--- docker/docker-compose.yml | 56 +++++++++++---------------------------- 2 files changed, 24 insertions(+), 44 deletions(-) diff --git a/README.sh b/README.sh index 985d1df..b64be02 100755 --- a/README.sh +++ b/README.sh @@ -4,12 +4,12 @@ IMAGE=juplo/spring-consumer-json:1.0-SNAPSHOT if [ "$1" = "cleanup" ] then - docker-compose -f docker/docker-compose.yml down -v --remove-orphans + docker-compose -f docker/docker-compose.yml down -t0 -v --remove-orphans mvn clean exit fi -docker-compose -f docker/docker-compose.yml up -d kafka-1 kafka-2 kafka-3 cli +docker-compose -f docker/docker-compose.yml up -d kafka-1 kafka-2 kafka-3 docker-compose -f docker/docker-compose.yml rm -svf consumer-1 consumer-2 if [[ @@ -23,8 +23,12 @@ else docker image ls $IMAGE fi -docker-compose -f docker/docker-compose.yml up -d -docker-compose -f docker/docker-compose.yml logs -f setup +echo "Waiting for the Kafka-Cluster to become ready..." +docker-compose -f docker/docker-compose.yml run --rm cli cub kafka-ready -b kafka:9092 3 60 > /dev/null 2>&1 || exit 1 + +docker-compose -f docker/docker-compose.yml up -t0 -d cli + +docker-compose -f docker/docker-compose.yml up -d producer consumer-1 consumer-2 while ! [[ $(http 0:8080/actuator/health 2> /dev/null) =~ "UP" ]]; do echo "Waiting for producer..."; sleep 1; done while ! [[ $(http 0:8081/actuator/health 2> /dev/null) =~ "UP" ]]; do echo "Waiting for consumer-1..."; sleep 1; done diff --git a/docker/docker-compose.yml b/docker/docker-compose.yml index 7324b30..0a137f8 100644 --- a/docker/docker-compose.yml +++ b/docker/docker-compose.yml @@ -1,54 +1,35 @@ version: '3.2' services: - kafka-0: - image: bitnami/kafka:3.3.1 - environment: - KAFKA_ENABLE_KRAFT: 'yes' - KAFKA_KRAFT_CLUSTER_ID: r7dMBY60T16TrNCGeXniLw - KAFKA_CFG_PROCESS_ROLES: controller - KAFKA_CFG_CONTROLLER_LISTENER_NAMES: CONTROLLER - KAFKA_CFG_LISTENERS: CONTROLLER://:9092 - KAFKA_CFG_ADVERTISED_LISTENERS: " " - KAFKA_CFG_LISTENER_SECURITY_PROTOCOL_MAP: CONTROLLER:PLAINTEXT - KAFKA_BROKER_ID: 0 - KAFKA_CFG_CONTROLLER_QUORUM_VOTERS: 0@kafka-0:9092 - ALLOW_PLAINTEXT_LISTENER: 'yes' - KAFKA_CFG_OFFSETS_TOPIC_REPLICATION_FACTOR: 1 - KAFKA_CFG_AUTO_CREATE_TOPICS_ENABLE: "false" kafka-1: - image: bitnami/kafka:3.3.1 + image: bitnami/kafka:3.4 environment: KAFKA_ENABLE_KRAFT: 'yes' KAFKA_KRAFT_CLUSTER_ID: r7dMBY60T16TrNCGeXniLw - KAFKA_CFG_PROCESS_ROLES: broker KAFKA_CFG_CONTROLLER_LISTENER_NAMES: CONTROLLER - KAFKA_CFG_LISTENERS: BROKER://:9092, LOCALHOST://:9081 + KAFKA_CFG_LISTENERS: CONTROLLER://:9093, BROKER://:9092, LOCALHOST://:9081 KAFKA_CFG_LISTENER_SECURITY_PROTOCOL_MAP: BROKER:PLAINTEXT, CONTROLLER:PLAINTEXT, LOCALHOST:PLAINTEXT KAFKA_CFG_ADVERTISED_LISTENERS: BROKER://kafka-1:9092, LOCALHOST://localhost:9081 - KAFKA_BROKER_ID: 1 - KAFKA_CFG_CONTROLLER_QUORUM_VOTERS: 0@kafka-0:9092 + KAFKA_CFG_NODE_ID: 1 + KAFKA_CFG_CONTROLLER_QUORUM_VOTERS: 1@kafka-1:9093, 2@kafka-2:9093, 3@kafka-3:9093 ALLOW_PLAINTEXT_LISTENER: 'yes' KAFKA_CFG_INTER_BROKER_LISTENER_NAME: BROKER KAFKA_CFG_OFFSETS_TOPIC_REPLICATION_FACTOR: 3 KAFKA_CFG_AUTO_CREATE_TOPICS_ENABLE: "false" ports: - 9081:9081 - depends_on: - - kafka-0 kafka-2: - image: bitnami/kafka:3.3.1 + image: bitnami/kafka:3.4 environment: KAFKA_ENABLE_KRAFT: 'yes' KAFKA_KRAFT_CLUSTER_ID: r7dMBY60T16TrNCGeXniLw - KAFKA_CFG_PROCESS_ROLES: broker KAFKA_CFG_CONTROLLER_LISTENER_NAMES: CONTROLLER - KAFKA_CFG_LISTENERS: BROKER://:9092, LOCALHOST://:9082 + KAFKA_CFG_LISTENERS: CONTROLLER://:9093, BROKER://:9092, LOCALHOST://:9082 KAFKA_CFG_LISTENER_SECURITY_PROTOCOL_MAP: BROKER:PLAINTEXT, CONTROLLER:PLAINTEXT, LOCALHOST:PLAINTEXT KAFKA_CFG_ADVERTISED_LISTENERS: BROKER://kafka-2:9092, LOCALHOST://localhost:9082 - KAFKA_BROKER_ID: 2 - KAFKA_CFG_CONTROLLER_QUORUM_VOTERS: 0@kafka-0:9092 + KAFKA_CFG_NODE_ID: 2 + KAFKA_CFG_CONTROLLER_QUORUM_VOTERS: 1@kafka-1:9093, 2@kafka-2:9093, 3@kafka-3:9093 ALLOW_PLAINTEXT_LISTENER: 'yes' KAFKA_CFG_INTER_BROKER_LISTENER_NAME: BROKER KAFKA_CFG_OFFSETS_TOPIC_REPLICATION_FACTOR: 3 @@ -60,29 +41,24 @@ services: default: aliases: - kafka - depends_on: - - kafka-0 kafka-3: - image: bitnami/kafka:3.3.1 + image: bitnami/kafka:3.4 environment: KAFKA_ENABLE_KRAFT: 'yes' KAFKA_KRAFT_CLUSTER_ID: r7dMBY60T16TrNCGeXniLw - KAFKA_CFG_PROCESS_ROLES: broker KAFKA_CFG_CONTROLLER_LISTENER_NAMES: CONTROLLER - KAFKA_CFG_LISTENERS: BROKER://:9092, LOCALHOST://:9083 + KAFKA_CFG_LISTENERS: CONTROLLER://:9093, BROKER://:9092, LOCALHOST://:9083 KAFKA_CFG_LISTENER_SECURITY_PROTOCOL_MAP: BROKER:PLAINTEXT, CONTROLLER:PLAINTEXT, LOCALHOST:PLAINTEXT KAFKA_CFG_ADVERTISED_LISTENERS: BROKER://kafka-3:9092, LOCALHOST://localhost:9083 - KAFKA_BROKER_ID: 3 - KAFKA_CFG_CONTROLLER_QUORUM_VOTERS: 0@kafka-0:9092 + KAFKA_CFG_NODE_ID: 3 + KAFKA_CFG_CONTROLLER_QUORUM_VOTERS: 1@kafka-1:9093, 2@kafka-2:9093, 3@kafka-3:9093 ALLOW_PLAINTEXT_LISTENER: 'yes' KAFKA_CFG_INTER_BROKER_LISTENER_NAME: BROKER KAFKA_CFG_OFFSETS_TOPIC_REPLICATION_FACTOR: 3 KAFKA_CFG_AUTO_CREATE_TOPICS_ENABLE: "false" ports: - 9083:9083 - depends_on: - - kafka-0 setup: @@ -91,13 +67,15 @@ services: bash -c " kafka-topics --bootstrap-server kafka:9092 --delete --if-exists --topic test kafka-topics --bootstrap-server kafka:9092 --create --topic test --partitions 2 --replication-factor 3 --config min.insync.replicas=2 + echo Das Topic \'test\' wurde erfolgreich angelegt: kafka-topics --bootstrap-server kafka:9092 --describe --topic test + echo \'docker-compose restart -t0 setup\' löscht das Topic und legt es neu an + sleep infinity " depends_on: - kafka-1 - kafka-2 - kafka-3 - - cli akhq: image: tchiotludo/akhq:0.23.0 @@ -119,9 +97,7 @@ services: image: juplo/toolbox command: sleep infinity depends_on: - - kafka-1 - - kafka-2 - - kafka-3 + - setup producer: image: juplo/rest-producer-json:1.0-SNAPSHOT -- 2.20.1