Skip to content
Latchkey

kafka-configs.sh: Read and Alter Configs

kafka-configs.sh --alter --entity-type topics --entity-name <t> --add-config <k=v> changes a topic config such as retention.ms without recreating the topic.

Tests sometimes need short retention or a specific cleanup policy on a topic. kafka-configs applies those settings to an existing topic or broker at runtime.

What it does

kafka-configs.sh reads and mutates dynamic configuration for topics, brokers, users, and clients. --describe lists effective configs; --alter with --add-config or --delete-config changes them. The entity is chosen with --entity-type and --entity-name.

Common usage

Terminal
kafka-configs.sh --bootstrap-server localhost:9092 \
  --describe --entity-type topics --entity-name orders
# shorten retention to 1 minute for a test
kafka-configs.sh --bootstrap-server localhost:9092 \
  --alter --entity-type topics --entity-name orders \
  --add-config retention.ms=60000
# remove the override again
kafka-configs.sh --bootstrap-server localhost:9092 \
  --alter --entity-type topics --entity-name orders \
  --delete-config retention.ms

Options

FlagWhat it does
--describeShow current configs for the entity
--alterChange configs
--entity-type <t>topics, brokers, users, or clients
--entity-name <name>Name of the topic/broker/user
--add-config <k=v[,...]>Set one or more config overrides
--delete-config <k[,...]>Remove config overrides

Common errors in CI

"Unknown topic or partition" means --entity-name points at a topic that does not exist; create it first. "Invalid config(s): retention.ms" means a misspelled key or a value outside its range. "Connection to node -1 ... could not be established" is the broker being down. Note that not every config is dynamically alterable; some require a broker restart and are rejected here.

Related guides

Run this faster and cheaper on Latchkey managed runners. Start free →