Skip to content
Related Articles
Get the best out of our app
Open App

Related Articles

Apache Kafka – Topics using CLI

Improve Article
Save Article
Like Article
Improve Article
Save Article
Like Article

In Apache Kafka, a topic is a category or stream of messages that the Kafka message broker (or cluster) stores. Producers write data to topics and consumers read from topics. A Topic in Kafka is similar to a table in a database or a stream in a stream processing system. Each topic is divided into a number of partitions, which allows for parallel processing of the data by consumers. Messages are assigned to partitions based on a partitioning key, which can be any field in the message. Topics are used to store and transmit data in Kafka. They can be used for a wide range of applications, such as real-time data processing, event-driven architectures, and log aggregation. A topic in Kafka can be created, deleted, described, or changed using the CLI. Make sure Kafka is open before you begin. The necessary parameters must be specified in order to describe a Kafka topic and obtain partition information.

  • Use the hostname and port for Kafka v2.2+, for example, localhost:9092.
  • Use localhost:2181 as the Zookeeper URL and port if you’re using a previous version of Kafka.

Create a Kafka Topic

  • The name of the topic, number of partitions, and replication factor are required parameters.
  • Use the “–create” option in the CLI

To create a Kafka topic called “topic1” with 3 partitions and a replication factor of 1, connect to the Kafka broker running at localhost:9092. --bootstrap-server localhost:9092 --topic topic1 --create --partitions 3 --replication-factor 1


Creating kafka topic.

Creating kafka topic

Additional important Parameters You Can Set (Advanced)


You may configure topics at the topic level, using a command like –config max.message.bytes=64000.


Disable rack-aware replica assignment (not advised; only set if you are confident in your ability to use it)

List Kafka Topic

Use the –list” option in the CLI for Listing topics when my Kafka broker is running at localhost:9092 --bootstrap-server localhost:9092 --list


Listing kafka topics

Listing kafka topics

Describe a Kafka Topic

In the CLI, use the “–describe option. Describing topics when my Kafka broker is running at localhost:9092 --bootstrap-server localhost:9092 --describe --topic topic1


Describing a kafka topic

Describing a kafka topic

These are some of the advanced parameters that can be used with “–list” and “–describe.”


When using the list or describe commands, ignore internal subjects (they are by default listed).

Using replication status as a filter for topics:


If enabled, only display partitions whose isr count is equal to the given minimum while explaining subjects.


Only display divisions with an unavailable leader.


A partition will only be shown if its isr count is below the defined minimum.


only display the under-replicated partitions.

My Personal Notes arrow_drop_up
Last Updated : 01 Feb, 2023
Like Article
Save Article
Similar Reads
Related Tutorials