-->
  • Recent Articles

    How to Manually delete Apache Kafka topics

    How to Manually delete Apache Kafka topics


    In Apache’s Kafka, deleting a topic is fairly easy. You need to Add the following line, or change the value of the property to true:

    delete.topic.enable=true

    Now go to the ‘bin’ directory, and run a executable file ‘kafka-topics.sh’. This is the file we’ll be using to delete a topic. The command to delete a topic is this:

    ./kafka-topics.sh --zookeeper localhost:2181 --delete --topic <topic_name>

    [root@kafkaserver ~]#  kafka-topics --zookeeper kafkaserver.ap-south-1.compute.internal:2181 --delete --topic gonecase
    Topic gonecase is marked for deletion.
    Note: This will have no impact if delete.topic.enable is not set to true.
    [root@kafkaserver ~]#

    Manually delete a topic with Zookeeper


    After you issue the delete command, the topic will be “marked for deletion,’ and you’ll have to wait till it gets deleted. Sometimes, it doesn’t happen. When you face this problem, you can use Zookeeper to delete a topic. First, log into the Zookeeper CLI console using the proper ‘zkCli.sh’ (For Opensource Kafka) file, you’ll find this in the ‘bin’ directory in your Zookeeper installation. For Confluent Kafka run "zookeeper-shell". In my case i'm using Confluent Kafka, so i'll explain this process with "zookeeper-shell".


    Once you’re in, make sure the topic is not deleted by issuing the following command:

    get /brokers/topics/<topic_name>
    If you don’t get an error, it means that topic is not yet deleted. Now run the following two commands to delete the topic completely from the system:

    rmr /brokers/topics/<topic_name>
    rmr /admin/delete_topics/<topic_name>

    Now if you try to ‘get’ the topic using the previous command, it’ll throw an error. And that’s it, you’re done. The topic is now deleted.
    kafka

    If you want to manage Kafka from GUI, Please follow this link for more details.

    No comments