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
topicsfunctionalitieskafka-topics.sh -
get list of
topicskafka-topics.sh --bootstrap-server <kafka-broker> --list -
create a
topickafka-topics.sh --bootstrap-server <kafka-broker> --topic <topic-name> --create -
create a
topicwithpartitionskafka-topics.sh --bootstrap-server <kafka-broker> --topic <topic-name> --create --partitions <number-of-partitions> -
create a
topicwithreplication-factorkafka-topics.sh --bootstrap-server <kafka-broker> --topic <topic-name> --create --replication-factor <replication-factor> -
create a
topicwithpartitionsandreplication-factorkafka-topics.sh --bootstrap-server <kafka-broker> --topic <topic-name> --create --partitions <number-of-partitions> --replication-factor <replication-factor> -
describe a
topickafka-topics.sh --bootstrap-server <kafka-broker> --topic <topic-name> --describe -
delete a
topickafka-topics.sh --bootstrap-server <kafka-broker> --topic <topic-name> --delete
Examples đ§Š
-
get help for
kafka-topicskafka-topics --help
-
list all
topicsin the clusterkafka-topics.sh --bootstrap-server localhost:9092 --list--bootstrap-serveris theKafka brokerto connect to
-
create a
topickafka-topics.sh --bootstrap-server localhost:9092 --create --topic first_topic
-
create a
topicwith apartitioncount of3kafka-topics.sh --bootstrap-server localhost:9092 --create --topic second_topic --partitions 3 -
create a
topicwith apartitioncount of3and areplication factorof2kafka-topics.sh --bootstrap-server localhost:9092 --create --topic third_topic --partitions 3 --replication-factor 2- will error since the
replication factoris greater than the number ofbrokersavailable
- will error since the
-
create a
topicwith apartitioncount of3and areplication factorof1kafka-topics.sh --bootstrap-server localhost:9092 --create --topic third_topic --partitions 3 --replication-factor 1- now it works since the
replication factoris less than or equal to the number ofbrokersavailable
- now it works since the
-
describe a
topickafka-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
topickafka-topics.sh --bootstrap-server localhost:9092 --delete --topic first_topic