如何删除一个主题在阿帕奇卡夫卡

我需要在卡夫卡 -0.8.2.2.3中删除一个主题。我使用了下面的命令来删除这个主题:

bin/kafka-topics.sh --zookeeper localhost:2181 --delete --topic DummyTopic

命令执行成功,但是当我运行一个命令来列出主题时,我可以看到主题仍然存在并显示 标记为删除的

bin/kafka-topics.sh --list --zookeeper localhost:2181
DummyTopic - marked for deletion

当我创建主题 DummyTopic 时,它会输出异常,主题已经存在,下面是堆栈跟踪:

Error while executing topic command Topic "DummyTopic" already exists.
kafka.common.TopicExistsException: Topic "DummyTopic" already exists.
at kafka.admin.AdminUtils$.createOrUpdateTopicPartitionAssignmentPathInZK(AdminUtils.scala:248)
at kafka.admin.AdminUtils$.createTopic(AdminUtils.scala:233)
at kafka.admin.TopicCommand$.createTopic(TopicCommand.scala:92)
at kafka.admin.TopicCommand$.main(TopicCommand.scala:54)
at kafka.admin.TopicCommand.main(TopicCommand.scala)

请让我知道如何删除这个主题。

247879 次浏览

Deletion of a topic has been supported since 0.8.2.x version. You have to enable topic deletion (setting delete.topic.enable to true) on all brokers first.

Note: Ever since 1.0.x, the functionality being stable, delete.topic.enable is by default true.

Follow this step by step process for manual deletion of topics

  1. Stop Kafka server
  2. Delete the topic directory, on each broker (as defined in the logs.dirs and log.dir properties) with rm -rf command
  3. Connect to Zookeeper instance: zookeeper-shell.sh host:port
  4. From within the Zookeeper instance:
    1. List the topics using: ls /brokers/topics
    2. Remove the topic folder from ZooKeeper using: rmr /brokers/topics/yourtopic
    3. Exit the Zookeeper instance (Ctrl+C)
  5. Restart Kafka server
  6. Confirm if it was deleted or not by using this command kafka-topics.sh --list --zookeeper host:port