Monday, 8 February 2021

How to create a Kafka Topic using command line utility ?

 Just a quick introduction, we can create Kafka Topic. using command line utility and also using programming APIs.

This post shows command line utility which help us in creating the Kafka Topic.

For your information, under /bin folder of Kafka installation, there are many Kafka Utilities available for various uses, one of which to kafka-topics.sh helps to create topics, describe topics & other topic related stuff.

Before executing the topic command as below, ensure your Zookeeper Server and Kafka Cluster (same order - start Zookeeper 1st then Kafka Cluster service next) has already been started.

Lets say Kafka cluster is having one node with its Kafka Service node running at a default port 9092 & we are trying to create a topic named error-events

$ bin/kafka-topics.sh --create --topic error-events --bootstrap-server localhost:9092

Console Output:

Topic created.

To ensure the topic creation, we can describe the topic:

$ bin/kafka-topics.sh --describe --topic error-events --bootstrap-server localhost:9092
Topic:error-events  PartitionCount:1    ReplicationFactor:1 Configs:
    Topic: error-events Partition: 0    Leader: 0   Replicas: 0 Isr: 0


It prints all the information related to given kafka topic - like partition count, replicator factor, replicas, in-sync replicas (Isr), Leader ...




No comments:

Post a Comment