Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow global topic configs #642

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,14 @@ Here is an example snippet from ```docker-compose.yml```:

```Topic 1``` will have 1 partition and 3 replicas, ```Topic 2``` will have 1 partition, 1 replica and a `cleanup.policy` set to `compact`. Also, see FAQ: [Topic compaction does not work](https://github.com/wurstmeister/kafka-docker/wiki#topic-compaction-does-not-work)

If you wish to use multi-line YAML or some other delimiter between your topic definitions, override the default `,` separator by specifying the `KAFKA_CREATE_TOPICS_SEPARATOR` environment variable.
If you'd like to add default configurations to all topics, for instance removing the retention, you can do it via:

environment:
KAFKA_CREATE_TOPICS_DEFAULT_CONFIG: "retention.ms=-1,retention.bytes=-1"

Check all available [Kafka topic configs](https://kafka.apache.org/documentation/#topicconfigs)

If you wish to use multi-line YAML or some other delimiter between your topic definitions and configs, override the default `,` separator by specifying the `KAFKA_CREATE_TOPICS_SEPARATOR` environment variable.

For example, `KAFKA_CREATE_TOPICS_SEPARATOR: "$$'\n'"` would use a newline to split the topic definitions. Syntax has to follow docker-compose escaping rules, and [ANSI-C](https://www.gnu.org/software/bash/manual/html_node/ANSI_002dC-Quoting.html) quoting.

Expand Down
11 changes: 10 additions & 1 deletion create-topics.sh
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,18 @@ if [[ "$MAJOR_VERSION" == "0" && "$MINOR_VERSION" -gt "9" ]] || [[ "$MAJOR_VERSI
KAFKA_0_10_OPTS="--if-not-exists"
fi

# Expected format:
# config=value,
# Available configs: https://kafka.apache.org/documentation/#topicconfigs
topicConfigDefault=
IFS="${KAFKA_CREATE_TOPICS_SEPARATOR-,}"; for config in $KAFKA_CREATE_TOPICS_DEFAULT_CONFIG; do
topicConfigDefault="${topicConfigDefault} --config=${config//[[:space:]]/}"
done

# Expected format:
# name:partitions:replicas:cleanup.policy
IFS="${KAFKA_CREATE_TOPICS_SEPARATOR-,}"; for topicToCreate in $KAFKA_CREATE_TOPICS; do
echo "creating topics: $topicToCreate"
echo "creating topics: $topicToCreate with default config \"$topicConfigDefault\""
IFS=':' read -r -a topicConfig <<< "$topicToCreate"
config=
if [ -n "${topicConfig[3]}" ]; then
Expand All @@ -49,6 +57,7 @@ IFS="${KAFKA_CREATE_TOPICS_SEPARATOR-,}"; for topicToCreate in $KAFKA_CREATE_TOP
--topic ${topicConfig[0]} \\
--partitions ${topicConfig[1]} \\
--replication-factor ${topicConfig[2]} \\
${topicConfigDefault} \\
${config} \\
${KAFKA_0_10_OPTS} &"
eval "${COMMAND}"
Expand Down