Java 如何在apache kafka中删除主题

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/33537950/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-11 14:45:35  来源:igfitidea点击:

How to Delete a topic in apache kafka

javaapache-kafka

提问by Rishi Arora

I need to delete a topic in kafka-0.8.2.2.3. I have used the below command for deleting the topic:

我需要在 kafka-0.8.2.2.3 中删除一个主题。我已使用以下命令删除主题:

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

The command executed successfully but when I run a command to list the topics, I could see that the topic is still there and it shows marked for deletion.

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

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

And when I create the topic DummyTopic it outputs the exception, The topic already exists, below is the stack trace:

当我创建主题 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)

Please let me know how can I delete this topic.

请告诉我如何删除此主题。

采纳答案by Ravindra babu

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

从 0.8.2.x 版本开始支持删除主题。您必须delete.topic.enable首先在所有代理上启用主题删除(设置为 true)。

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

注意:从 1.0.x 开始,功能稳定,delete.topic.enable默认为true

Follow this step by step process for manual deletion of topics

按照此分步过程手动删除主题

  1. Stop Kafkaserver
  2. Delete the topic directory, on each broker(as defined in the logs.dirsand log.dirproperties) with rm -rfcommand
  3. Connect to Zookeeperinstance: zookeeper-shell.sh host:port
  4. From within the Zookeeperinstance:
    1. List the topics using: ls /brokers/topics
    2. Remove the topic folder from ZooKeeperusing: rmr /brokers/topics/yourtopic
    3. Exit the Zookeeper instance (Ctrl+C)
  5. Restart Kafkaserver
  6. Confirm if it was deleted or not by using this command kafka-topics.sh --list --zookeeper host:port
  1. 停止Kafka服务器
  2. 删除主题目录,每个代理(如在定义logs.dirslog.dir属性)与rm -rf命令
  3. 连接到Zookeeper实例:zookeeper-shell.sh host:port
  4. Zookeeper实例中:
    1. 使用以下方法列出主题: ls /brokers/topics
    2. 使用以下命令从ZooKeeper 中删除主题文件夹:rmr /brokers/topics/yourtopic
    3. 退出 Zookeeper 实例 (Ctrl+C)
  5. 重启Kafka服务器
  6. 使用此命令确认是否已删除 kafka-topics.sh --list --zookeeper host:port