Learn Apache Kafka

Create or List or Describe a Kafka Topic

Kafka Topic

What is Kafka Topic?

A stream of messages belonging to a particular category is called a topic. Data is stored in topics.


Topics are split into partitions. For each topic, Kafka keeps a mini-mum of one partition. Each such partition contains messages in an immutable ordered sequence. A partition is implemented as a set of segment files of equal sizes.


1. Create a topic:

Note: - Make sure that both zookeepers, as well as the Kafka server, should be started.

Syntax: -

kafka-topics --create --topic topic_name --partitions no_of_partitions --replication-factor specify_no_of_replicas --zookeeper localhost:2181


In Windows: -

cmd> kafka-topics --create --topic cfamily --partitions 3 --replication-factor 1 --zookeeper localhost:2181


If Topic is already available then we will get error



In Linux: -

$ kafka-topics.sh --create --topic cfamily --partitions 3 --replication-factor 1 --zookeeper localhost:2181


Note: - Replication factor should not be more than no.of servers or brokers


2. Listing the number of Topics

è To list the number of topics created within a broker, we use '-list' option.

Syntax: -

cmd>kafka-topics -zookeeper localhost:2181 -list



 cmd>kafka-topics -zookeeper localhost:2181 -list


3. Describing a topic: -

Syntax: -

kafka-topics -zookeeper localhost:2181 -describe --topic <topic_name>

This command gives the whole description of a topic with the number of partitions, leader, replicas and, ISR.



cmd>kafka-topics -zookeeper localhost:2181 -describe --topic cfamily


4. Deleting a topic: -

è To delete a topic we use -delete.

Syntax: -

kafka-topics.sh -zookeeper localhost:2181 -topic <topic_name> --delete



cmd>kafka-topics -zookeeper localhost:2181 -topic cfamily –delete