Introduction to Kafka Delete Topic
As we all know, Kafka is providing the streaming solution. As per the requirement, we can design the Kafka architecture in such a way that the data should be available every time and it will be processed at every time. There is a producer concept in Kafka; it will help to generate the data in Kafka. Once the data will generate, there is a mechanism to consume the data also. But the generated data will be store on the specific Kafka topic only. The Kafka topic is responsible to hold the data as per the default data retention period. As per the day-to-day working with Kafka, we need to do proper management of the Kafka topics also. In the few version of Kafka, the deletion of the Topic is very easy. There are different ways to delete the Kafka topic like manual deletion of the Kafka topic, with the help of the zookeeper, etc.
kafka-topics.sh --zookeeper [ zookeeper host ] [ option | delete ] --topic [topic name]
1) Kafka-topics.sh: Here, we are using the Kafka topic script. We can use the topic script as the keyword in the syntax or Kafka delete command. It will accept different arguments like the zookeeper host, different options, topic name, etc. As per the provided input, the Kafka topic script will delete the respective topic which is provided in the command. It will remove the respective topic from the Kafka ecosystem. The Kafka topic script will help to delete the Kafka topic from the Kafka environment.
Note: The default path of the Kafka topic script is /usr/hdp/current/Kafka-broker/bin.
2) Zookeeper Node and Port: While deleting the Kafka topic, it is mandatory to provide the zookeeper host and port no.
Note: The default for the Zookeeper service is 2181.
3) OPTION: As per the requirement, we can provide the different flags as the option that is compatible with the Kafka topic script.
4) Topic name: As per the requirement or need, we can provide the topic name that we need to delete from the Kafka environment.
How Kafka delete topic works?
As we have discussed, there are different ways to delete the Kafka topic like we can delete the Kafka topic manually, from the tool we can delete the Kafka topic, from the script or the application job, etc. As per the requirement, we can select which method that we need to use to delete the Kafka topic. Ideally, we are using the manual method to delete the Kafka topic. Here, we are using the zookeeper host and the zookeeper host. But please keep in mind, while deleting such a topic. We need to make sure that the “delete.topic.enable” property should be available in the Kafka core configuration. In the same configure configuration the value of the property should be true only. It would not be set as true.
Once the property will be true, it will indicate that we are able to delete the Kafka topic easily. Now, we need to use the zookeeper host which is using in the Kafka environment. We need to use both the zookeeper host and the port. While deleting the Kafka topic, we need to use the option in the same command as delete. We need to use the Kafka topic name also that needs to be deleted. All the commands and the option should be manipulated with Kafka topic script and need to run it. As per the provided values, it will connect with the Kafka environment with the help of a zookeeper and then delete the respective Kafka topic from the Kafka environment.
Kafka delete topic: How to delete the Kafka topic
In the Kafka environment, we are having different ways to delete the Kafka topic. As per our requirement, we need to choose which suitable option that we need to check and adopt. Before deleting the Kafka topic, we need to take care few things like the configuration level. We need to do the changes in the Kafka configuration and add a few properties. Once, the property is added to the configuration. We are able to delete the Kafka topic from the Kafka environment.
Note: For this example, we are using the Kafka cluster. Hence we are doing the configuration level changes from the UI front. Because we are having the Ambari cluster manager hence the configuration will handle on a centralized level.
delete.topic.enable = true
./kafka-topics.sh --zookeeper 10.10.132.70:2181, 10.10.132.71:2181, 10.10.132.72:2181 --delete --topic test_topic
As per the above command, we are having two parts. In the first part, we are adding the configuration property in the Kafka configuration. As per the below screenshot 1 (a), we have added the configuration property in the Kafka centralized configuration. The value is deleted.topic.enable. We need to set the value of this property as true. By default, the value is available in the configuration only. But in some cases, where we are using the standalone Kafka environment we need to add the configuration property manually.
In screenshot 1 (b), we are actually deleting the Kafka topic. In the same screenshot, first, we are listing the list of topic in the Kafka environment with the help of below command then it will print the number of topics which is available under the Kafka environment. Here we are deleting the “test_topic” topic.
Kafka list topic : ./kafka-topics.sh –list –zookeeper 10.10.132.70:2181
Screenshot 1 (a)
Screenshot 1 (b)
We have seen the uncut concept of the “Kafka delete topic” with the proper example, explanation, and command with different outputs. In the Kafka environment, we are able to delete any topic from the Kafka environment. Before deleting the Kafka topic, we need to make sure that the delete. topic. enable configuration property should be available in the Kafka configuration. The values of the same property should be “true” only.
This is a guide to Kafka Delete Topic. Here we discuss Introduction, syntax, How Kafka delete topic Works? example with code implementation. You may also have a look at the following articles to learn more –