You need to make sure both zookeeper and Kafka server are running before executing the commands. Please check the installation steps on Windows if you have not configure them yet.
Creating a Kafka Topic:
Go to C:\Work\Kafka\kafka_2.12-2.8.0\bin\windows directory and use the following syntax to create a Kafka Topic.
Kafka-topics.bat –create –zookeeper 127.0.0.1:2181 --replication-factor <replicaCount> –partitions <partitionCoun> --topic <topicname> Example: Kafka-topics.bat –create –zookeeper 127.0.0.1:2181 --replication-factor 1 –partitions 1 --topic msgtest
Output:
You need to use replication-factor value as 1 since we are using single Kafka broker/node.
If you are using replication-factor more than 1, you will get the InvalidReplicationFactorException error as we have only one broker.
To view the created topics in Kafka broker, use ‘’-list’’ command.
Kafka-topics.bat –zookeeper 127.0.0.1:2181 –list
To know the complete details about the Kafka topic within the broker, use “—describe” command.
Kafka-topics.bat –zookeeper 127.0.0.1:2181 –describe –topic <topicname>
You can find the number of partitions, leader, replicas and ISR details in detailed view of the topic.
To delete a Kafka topic, use “–delete” command.
Kafka-topics.bat –zookeeper 127.0.0.1:2181 –delete –topic <topicname>
You can see the existing topics below within the Kafka broker.
Use the following command, to delete the specific Kafka topic.
Kafka-topics.bat –zookeeper 127.0.0.1:2181 –delete –topic msgtest Output: