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
How to Delete a topic in apache 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.enable
to 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.enable
is by default true
.
注意:从 1.0.x 开始,功能稳定,delete.topic.enable
默认为true
。
Follow this step by step process for manual deletion of topics
按照此分步过程手动删除主题
- Stop Kafkaserver
- Delete the topic directory, on each broker(as defined in the
logs.dirs
andlog.dir
properties) withrm -rf
command - Connect to Zookeeperinstance:
zookeeper-shell.sh host:port
- From within the Zookeeperinstance:
- List the topics using:
ls /brokers/topics
- Remove the topic folder from ZooKeeperusing:
rmr /brokers/topics/yourtopic
- Exit the Zookeeper instance (Ctrl+C)
- List the topics using:
- Restart Kafkaserver
- Confirm if it was deleted or not by using this command
kafka-topics.sh --list --zookeeper host:port
- 停止Kafka服务器
- 删除主题目录,每个代理(如在定义
logs.dirs
和log.dir
属性)与rm -rf
命令 - 连接到Zookeeper实例:
zookeeper-shell.sh host:port
- 从Zookeeper实例中:
- 使用以下方法列出主题:
ls /brokers/topics
- 使用以下命令从ZooKeeper 中删除主题文件夹:
rmr /brokers/topics/yourtopic
- 退出 Zookeeper 实例 (Ctrl+C)
- 使用以下方法列出主题:
- 重启Kafka服务器
- 使用此命令确认是否已删除
kafka-topics.sh --list --zookeeper host:port