kafka-topics
command line interface.
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.
Caution: Increasing the number of partitions in a Kafka topic is a DANGEROUS OPERATION if your applications are relying on key-based ordering.
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.