kafka-topics CLI is your primary tool for creating, listing, describing, altering, and deleting Kafka topics.
What you’ll learn:
- How to create topics with specific partitions and replication factor
- How to list and describe existing topics
- How to alter topic partition count
- How to delete topics
How to create a Kafka topic?
To create a Kafka topic, you need to provide:- Kafka hostname and port (e.g.,
localhost:9092) - Topic name
- Number of partitions
- Replication factor
Example
Creating a topic namedfirst_topic with 3 partitions and replication factor of 1:
For Kafka v2.2+:
Important gotchas
- Cannot specify a replication factor greater than the number of brokers
- No default values for partitions and replication factor
- Topic name must contain only ASCII alphanumerics, ’.’, ’_’ and ’-‘
How to list Kafka topics?
Usekafka-topics with the --list option.
Example
For Kafka v2.2+:How to describe a Kafka topic?
Usekafka-topics with the --describe option.
Example
For Kafka v2.2+:How to increase the number of partitions?
Usekafka-topics with the --alter option.
Example
How to delete a Kafka topic?
Usekafka-topics with the --delete option.
Example
Ensure
delete.topic.enable=true is set on brokers for deletion to work properly.Quick reference
| Operation | Command |
|---|---|
| Create topic | kafka-topics --bootstrap-server localhost:9092 --create --topic NAME --partitions N --replication-factor R |
| List topics | kafka-topics --bootstrap-server localhost:9092 --list |
| Describe topic | kafka-topics --bootstrap-server localhost:9092 --describe --topic NAME |
| Add partitions | kafka-topics --bootstrap-server localhost:9092 --alter --topic NAME --partitions N |
| Delete topic | kafka-topics --bootstrap-server localhost:9092 --delete --topic NAME |
See it in practice with ConduktorConduktor Console provides a visual interface for topic management. Create, configure, and monitor topics without memorizing CLI syntax.
Next steps
- Produce messages to your new topic
- Consume messages from topics
- Configure topic settings for production