Kafka Topic CLI commands
What is Kafka-Topic?
Apache Kafka is a real time-event driven platform, a distributed streaming platform. Where Topics are streams of related messages in Kafka. It is a logical representation of categorized messages into groups.
Producers writes to Kafka platform & it responds with acknowledgement or negative acknowledgement.
Brokers are local storage which stores the data of producers into pages(Basically, are servers). Kafka keeps clusters of brokers.
Consumers ask/trigger Kafka brokers continuously asking for data if available, called as polling.
- Developers define Topics.
- Producer → Topic is a N → N relationship. One can create unimitated number of topics.
- Topics are sub-categorized into Partitions & further into Segments.
Kafka-Topic CLI Commands:
To List out all the commands associated with kafka, to Create, delete, describe, or change a topic can be listed out by executing ‘kafka-topics’ batch file.
D:\kafka_2.12–2.5.0\bin\windows>kafka-topics.bat
Further demonstrating each command and it’s functioning:
- Create a topic:
D:\kafka_2.12–2.5.0\bin\windows>kafka-topics.bat — zookeeper localhost:2181 — topic <topic_name> — create — partitions <number_of_partitions> — replication-factor <total_replicas>example: kafka-topics.bat — zookeeper localhost:2181 — topic mytopic — create — partitions 3 — replication-factor 1
output:
Created topic mytopic.
2. Describe a topic:
D:\kafka_2.12–2.5.0\bin\windows>kafka-topics.bat — zookeeper localhost:2181 — topic <topic_name> — describeexample: kafka-topics.bat — zookeeper localhost:2181 — topic mytopic — describe
output:
Topic: mytopic PartitionCount: 3 ReplicationFactor: 1 Configs:
Topic: mytopic Partition: 0 Leader: 0 Replicas: 0 Isr: 0
Topic: mytopic Partition: 1 Leader: 0 Replicas: 0 Isr: 0
Topic: mytopic Partition: 2 Leader: 0 Replicas: 0 Isr: 0
3. List all the topic in the cluster:
D:\kafka_2.12–2.5.0\bin\windows>kafka-topics.bat — zookeeper localhost:2181 — list
output:
mytopic
4. Delete a topic:
D:\kafka_2.12–2.5.0\bin\windows>kafka-topics.bat — zookeeper localhost:2181 — topic <topic_name> — deleteexample: kafka-topics.bat — zookeeper localhost:2181 — topic mytopic — delete
output:
Topic mytopic is marked for deletion.
Note: This will have no impact if delete.topic.enable is not set to true.
SAMPLE:
That’s it! Don’t look any further.