We can also use the Kafka CLI to test, debug, and perform the audits on the cluster. We can also use them to perform the tasks on remote clusters with remote access tools such as SSH.
This tutorial provides you with some of the fundamental and basic commands for the Kafka CLI tools. This can make you better understand your system and improve efficiency without a heavy learning curve.
Kafka CLI Tools Location
Although the location of the Kafka CLI tools may differ depending on the installation method and system, they are located in the install_dir/bin directory by default. The install_dir refers to the directory where the Apache Kafka is installed.
Kafka Start Services Commands
The following commands are useful to start the various Kafka services. To start the Zookeeper service, run the following command:
To start the Kafka server, run the command:
Commands to Manage Your Kafka Topics
The following are some of the most common commands that you can use to manage your Kafka topics.
To create a Kafka topic, use the following command:
To view the details of a given Kafka topics, use the following command:
To list the topics that are available in the cluster, use the following command:
Kafka Publisher Commands
Once you create a topic, you can write the events using the “kafka-console-producer.sh” utilities.
To write the events to a given Kafka topic, use the following command:
You can then start writing the events to the topic. Once done, you can send a SIGKILL signal to the input buffer by pressing CTRL + C.
Other options that are accepted by the “Kafka-console-producer.sh” utility include the following:
- –compression-code – It specifies the message compression format such as none, gzip, snappy, or zstd.
- –producer – This allows you to specify the producer properties.
- –request-required-acks – This option enables you to set the acks settings.
Kafka Consumer Commands
To read the messages from a given topic, you can use the “kafka-console-consumer.sh” tool. The command is shown in the following:
Kafka Alter Topic
To add the partitions to an existing topic, you can use the following command:
Once you are done with a topic, you can delete it using the following command:
Kafka Consumer Group
To create a new consumer group, use the following command:
To stop the kafka consumer group, use the following command:
This command stops the consumer group “my-group” and resets its offsets to 0.
To list the consumer groups, use the following command:
To delete a specific consumer group, use the following command:
Conclusion
This post outlined some of the most fundamental and practical commands that you can use to work with the CLI commands in Apache Kafka. You can print this list to allow you to quickly reference the commands with ease.