Kafka - Topics CLI
đŋ
Refer back to the theories section for more information on topics.
Description đ
Used for Kafka
topic management. (i.e create, delete, list, describe, etc.)
Basic Commands
đ
-
get
topics
functionalitieskafka-topics.sh
-
get list of
topics
kafka-topics.sh --bootstrap-server <kafka-broker> --list
-
create a
topic
kafka-topics.sh --bootstrap-server <kafka-broker> --topic <topic-name> --create
-
create a
topic
withpartitions
kafka-topics.sh --bootstrap-server <kafka-broker> --topic <topic-name> --create --partitions <number-of-partitions>
-
create a
topic
withreplication-factor
kafka-topics.sh --bootstrap-server <kafka-broker> --topic <topic-name> --create --replication-factor <replication-factor>
-
create a
topic
withpartitions
andreplication-factor
kafka-topics.sh --bootstrap-server <kafka-broker> --topic <topic-name> --create --partitions <number-of-partitions> --replication-factor <replication-factor>
-
describe a
topic
kafka-topics.sh --bootstrap-server <kafka-broker> --topic <topic-name> --describe
-
delete a
topic
kafka-topics.sh --bootstrap-server <kafka-broker> --topic <topic-name> --delete
Examples đ§Š
-
get help for
kafka-topics
kafka-topics --help
-
list all
topics
in the clusterkafka-topics.sh --bootstrap-server localhost:9092 --list
--bootstrap-server
is theKafka broker
to connect to
-
create a
topic
kafka-topics.sh --bootstrap-server localhost:9092 --create --topic first_topic
-
create a
topic
with apartition
count of3
kafka-topics.sh --bootstrap-server localhost:9092 --create --topic second_topic --partitions 3
-
create a
topic
with apartition
count of3
and areplication factor
of2
kafka-topics.sh --bootstrap-server localhost:9092 --create --topic third_topic --partitions 3 --replication-factor 2
- will error since the
replication factor
is greater than the number ofbrokers
available
- will error since the
-
create a
topic
with apartition
count of3
and areplication factor
of1
kafka-topics.sh --bootstrap-server localhost:9092 --create --topic third_topic --partitions 3 --replication-factor 1
- now it works since the
replication factor
is less than or equal to the number ofbrokers
available
- now it works since the
-
describe a
topic
kafka-topics.sh --bootstrap-server localhost:9092 --describe --topic third_topic
-
output
đ kafka-zero-to-pro â kafka-topics.sh --bootstrap-server localhost:9092 --describe --topic third_topic Topic: third_topic TopicId: ePbXIDTPToa3OP2q_UAqYw PartitionCount: 3 ReplicationFactor: 1 Configs: segment.bytes=1073741824 Topic: third_topic Partition: 0 Leader: 1 Replicas: 1 Isr: 1 Topic: third_topic Partition: 1 Leader: 1 Replicas: 1 Isr: 1 Topic: third_topic Partition: 2 Leader: 1 Replicas: 1 Isr: 1
-
-
delete a
topic
kafka-topics.sh --bootstrap-server localhost:9092 --delete --topic first_topic