Skip to content

Commit

Permalink
Simplify skipping create Kafka topics when needed
Browse files Browse the repository at this point in the history
  • Loading branch information
jfallows committed Apr 30, 2024
1 parent e08c14e commit 9c6ff10
Showing 1 changed file with 10 additions and 8 deletions.
18 changes: 10 additions & 8 deletions mqtt.kafka.broker/docker/compose/setup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,16 @@ NAMESPACE=zilla-mqtt-kafka-broker
if [[ -z $(docker-compose -p $NAMESPACE ps -q zilla) ]]; then
docker-compose -p $NAMESPACE up -d

# Create the mqtt topics in Kafka
docker run --rm bitnami/kafka:3.2 bash -c "
echo 'Creating topics for $KAFKA_HOST:$KAFKA_PORT'
/opt/bitnami/kafka/bin/kafka-topics.sh --bootstrap-server $KAFKA_HOST:$KAFKA_PORT --create --if-not-exists --topic mqtt-messages
/opt/bitnami/kafka/bin/kafka-topics.sh --bootstrap-server $KAFKA_HOST:$KAFKA_PORT --create --if-not-exists --topic mqtt-devices --config cleanup.policy=compact
/opt/bitnami/kafka/bin/kafka-topics.sh --bootstrap-server $KAFKA_HOST:$KAFKA_PORT --create --if-not-exists --topic mqtt-retained --config cleanup.policy=compact
/opt/bitnami/kafka/bin/kafka-topics.sh --bootstrap-server $KAFKA_HOST:$KAFKA_PORT --create --if-not-exists --topic mqtt-sessions --config cleanup.policy=compact
"
if [[ "$KAFKA_SKIP_CREATE_TOPICS" != "yes" ]]; then
# Create the mqtt topics in Kafka
docker run --rm bitnami/kafka:3.2 bash -c "
echo 'Creating topics for $KAFKA_HOST:$KAFKA_PORT'
/opt/bitnami/kafka/bin/kafka-topics.sh --bootstrap-server $KAFKA_HOST:$KAFKA_PORT --create --if-not-exists --topic mqtt-messages
/opt/bitnami/kafka/bin/kafka-topics.sh --bootstrap-server $KAFKA_HOST:$KAFKA_PORT --create --if-not-exists --topic mqtt-devices --config cleanup.policy=compact
/opt/bitnami/kafka/bin/kafka-topics.sh --bootstrap-server $KAFKA_HOST:$KAFKA_PORT --create --if-not-exists --topic mqtt-retained --config cleanup.policy=compact
/opt/bitnami/kafka/bin/kafka-topics.sh --bootstrap-server $KAFKA_HOST:$KAFKA_PORT --create --if-not-exists --topic mqtt-sessions --config cleanup.policy=compact
"
fi

else
docker-compose -p $NAMESPACE restart --no-deps zilla
Expand Down

0 comments on commit 9c6ff10

Please sign in to comment.