This article describes how to create Apache Kafka topic and explains how to describe newly created and list all existing topics in Kafka. Producers publish and consumer receives messages to/from topics
Related: Ways to Delete messages from Kafka topic
1. Create Kafka Topic
All massages to and from Apache Kafka will happen via topics. Kafka by default creates a topic when we send a message to a non existing topic. This defines at $KAFKA_HOME/conf/server.properties
properties file with auto.create.topics.enable
is set to true (by default),
To create a Apache Kafka topic by command, run kafka-topics.sh
and specify topic name, replication factor, and other attributes. Producers write data to topics and consumers read from topics.
bin/kafka-topics.sh --zookeeper localhost:2181 \
--create \
--topic text_topic \
--replication-factor 1 --partitions 1
This will create a topic “text_topic” with replication factor 1 and partition 1.
2. Describe Kafka Topic
Describes newly created topic by running following command with option .–describe –topic This command returns leader broker id, replication factor and partition details of the topic.
bin/kafka-topics.sh --zookeeper localhost:2181 \
--describe --topic text_topic
3. Describe All Topics
Option –describe returns description of all existing topics
bin/kafka-topics.sh --zookeeper localhost:2181 \
--describe
4. List All Topics
Option –list returns all topics present in Kafka
bin/kafka-topics.sh --zookeeper localhost:2181 --list
Conclusion:
In this article, you have learned how to create a Kafka topic and describe all and a specific topic using kafka-topics.sh.