From b0a36f18b464fb0b1b21f0fd3bd1378cf3bc90fb Mon Sep 17 00:00:00 2001 From: Francis Cao Date: Tue, 2 Aug 2022 09:29:24 -0700 Subject: [PATCH] docker kafka auto-create topics --- docker-compose-kafka-multi.yml | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/docker-compose-kafka-multi.yml b/docker-compose-kafka-multi.yml index 5f031e0a..280bc746 100644 --- a/docker-compose-kafka-multi.yml +++ b/docker-compose-kafka-multi.yml @@ -70,4 +70,25 @@ services: KAFKA_AUTHORIZER_CLASS_NAME: kafka.security.authorizer.AclAuthorizer KAFKA_ALLOW_EVERYONE_IF_NO_ACL_FOUND: "true" depends_on: - - zoo1 \ No newline at end of file + - zoo1 + + init-kafka: + image: confluentinc/cp-kafka:7.2.0 + depends_on: + - kafka1 + - kafka2 + - kafka3 + entrypoint: [ '/bin/sh', '-c' ] + command: | + " + # blocks until kafka is reachable + kafka-topics --bootstrap-server kafka1:19092 --list + + echo -e 'Creating kafka topics' + kafka-topics --bootstrap-server kafka1:19092 --create --if-not-exists --topic pageview --replication-factor 3 --partitions 3 + kafka-topics --bootstrap-server kafka2:19093 --create --if-not-exists --topic event --replication-factor 3 --partitions 3 + kafka-topics --bootstrap-server kafka3:19094 --create --if-not-exists --topic session --replication-factor 3 --partitions 3 + + echo -e 'Successfully created the following topics:' + kafka-topics --bootstrap-server kafka1:19092 --list + " \ No newline at end of file