From 0fcf56b90308119d68011305b26db2f41aec1cad Mon Sep 17 00:00:00 2001 From: Denis Gontcharov Date: Thu, 7 Jan 2021 17:13:02 +0100 Subject: [PATCH] Added the option to specify topic.retention.ms during topic creation in create-topics.sh --- create-topics.sh | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/create-topics.sh b/create-topics.sh index 0bacf7b5..a7d6a8c0 100755 --- a/create-topics.sh +++ b/create-topics.sh @@ -34,7 +34,7 @@ if [[ "$MAJOR_VERSION" == "0" && "$MINOR_VERSION" -gt "9" ]] || [[ "$MAJOR_VERSI fi # Expected format: -# name:partitions:replicas:cleanup.policy +# name:partitions:replicas:cleanup.policy:retention.ms IFS="${KAFKA_CREATE_TOPICS_SEPARATOR-,}"; for topicToCreate in $KAFKA_CREATE_TOPICS; do echo "creating topics: $topicToCreate" IFS=':' read -r -a topicConfig <<< "$topicToCreate" @@ -52,6 +52,18 @@ IFS="${KAFKA_CREATE_TOPICS_SEPARATOR-,}"; for topicToCreate in $KAFKA_CREATE_TOP ${config} \\ ${KAFKA_0_10_OPTS} &" eval "${COMMAND}" + + if [ -n "${topicConfig[4]}" ]; then + wait + echo "setting retention of topic ${topicConfig[0]} to ${topicConfig[4]} ms" + SET_RETENTION=" ${KAFKA_HOME}/bin/kafka-configs.sh \\ + --zookeeper ${KAFKA_ZOOKEEPER_CONNECT} \\ + --alter \\ + --entity-type topics \\ + --entity-name ${topicConfig[0]} \\ + --add-config 'retention.ms=${topicConfig[4]}'" + eval "${SET_RETENTION}" + fi done wait