From: Kai Moritz Date: Sun, 11 Jun 2023 15:12:15 +0000 (+0200) Subject: Übung an die Docker-Übung angepasst X-Git-Tag: first-contact-DEPRECATED X-Git-Url: http://juplo.de/gitweb/?a=commitdiff_plain;h=refs%2Fheads%2Fgrundlagen%2Ffirst-contact;p=demos%2Fkafka%2Ftraining Übung an die Docker-Übung angepasst --- diff --git a/README.sh b/README.sh index 7ddfbbf..ddf55fa 100755 --- a/README.sh +++ b/README.sh @@ -2,7 +2,7 @@ if [ "$1" = "cleanup" ] then - docker-compose -f docker/docker-compose.yml down -v + docker-compose -f docker/docker-compose.yml down -t0 -v --remove-orphans mvn clean exit fi @@ -12,20 +12,27 @@ if [ "$1" = "build" ]; then exit; fi trap 'kill $(jobs -p) 2>/dev/null' EXIT -docker-compose -f docker/docker-compose.yml up -d - +docker-compose -f docker/docker-compose.yml up -d kafka-1 kafka-2 kafka-3 +docker-compose -f docker/docker-compose.yml ps echo "Waiting for the Kafka-Cluster to become ready..." -docker-compose -f docker/docker-compose.yml exec cli cub kafka-ready -b kafka:9092 1 60 > /dev/null 2>&1 || exit 1 +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 +sleep 1 +docker-compose -f docker/docker-compose.yml logs setup +echo echo "Producing messages" mvn exec:java@producer +echo echo "Reading messages" mvn exec:java@consumer & sleep 7 kill $(jobs -p) sleep 2 +echo echo "Re-Reading messages" mvn exec:java@consumer & sleep 7 diff --git a/docker/docker-compose.yml b/docker/docker-compose.yml index ec307f5..aead435 100644 --- a/docker/docker-compose.yml +++ b/docker/docker-compose.yml @@ -1,37 +1,100 @@ version: '3.2' services: - zookeeper: - image: confluentinc/cp-zookeeper:7.1.3 + + kafka-1: + image: bitnami/kafka:3.4 environment: - ZOOKEEPER_CLIENT_PORT: 2181 + KAFKA_ENABLE_KRAFT: 'yes' + KAFKA_KRAFT_CLUSTER_ID: r7dMBY60T16TrNCGeXniLw + KAFKA_CFG_CONTROLLER_LISTENER_NAMES: CONTROLLER + 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_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: - - 2181:2181 + - 9081:9081 - kafka: - image: confluentinc/cp-kafka:7.1.3 + kafka-2: + image: bitnami/kafka:3.4 environment: - KAFKA_BROKER_ID: 1 - KAFKA_ZOOKEEPER_CONNECT: zookeeper:2181 - KAFKA_LISTENERS: DOCKER://:9092, LOCALHOST://:9082 - KAFKA_ADVERTISED_LISTENERS: DOCKER://kafka:9092, LOCALHOST://localhost:9082 - KAFKA_INTER_BROKER_LISTENER_NAME: DOCKER - KAFKA_LISTENER_SECURITY_PROTOCOL_MAP: DOCKER:PLAINTEXT, LOCALHOST:PLAINTEXT - KAFKA_OFFSETS_TOPIC_REPLICATION_FACTOR: 1 - KAFKA_AUTO_CREATE_TOPICS_ENABLE: "false" + KAFKA_ENABLE_KRAFT: 'yes' + KAFKA_KRAFT_CLUSTER_ID: r7dMBY60T16TrNCGeXniLw + KAFKA_CFG_CONTROLLER_LISTENER_NAMES: CONTROLLER + 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_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 + KAFKA_CFG_AUTO_CREATE_TOPICS_ENABLE: "false" ports: - 9092:9082 - 9082:9082 - depends_on: - - zookeeper + networks: + default: + aliases: + - kafka + + kafka-3: + image: bitnami/kafka:3.4 + environment: + KAFKA_ENABLE_KRAFT: 'yes' + KAFKA_KRAFT_CLUSTER_ID: r7dMBY60T16TrNCGeXniLw + KAFKA_CFG_CONTROLLER_LISTENER_NAMES: CONTROLLER + 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_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 + setup: image: juplo/toolbox command: > bash -c " kafka-topics --bootstrap-server kafka:9092 --delete --if-exists --topic test - kafka-topics --bootstrap-server kafka:9092 --create --topic test --partitions 2 + 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 + + akhq: + image: tchiotludo/akhq:0.23.0 + ports: + - 8000:8080 + environment: + AKHQ_CONFIGURATION: | + akhq: + connections: + docker-kafka-server: + properties: + bootstrap.servers: "kafka:9092" + depends_on: + - kafka-1 + - kafka-2 + - kafka-3 cli: image: juplo/toolbox command: sleep infinity + depends_on: + - setup