如何在apache kafka中删除主题 [英] How to Delete a topic in apache kafka
问题描述
我需要在 kafka-0.8.2.2.3 中删除一个主题.我已使用以下命令删除主题:
I need to delete a topic in kafka-0.8.2.2.3. I have used the below command for deleting the topic:
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
当我创建主题 DummyTopic 时,它输出异常,主题已经存在,下面是堆栈跟踪:
And when I create the topic DummyTopic it outputs the exception, The topic already exists, below is the stack trace:
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.
推荐答案
从 0.8.2.x 版本开始支持删除主题.您必须首先在所有代理上启用主题删除(将 delete.topic.enable
设置为 true).
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.
注意:从 1.0.x 开始,功能稳定,delete.topic.enable
默认为 true
.
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
- 停止Kafka服务器
- 使用
删除每个 broker(在
命令logs.dirs
和log.dir
属性中定义)上的主题目录rm -rf - 连接到 Zookeeper 实例:
zookeeper-shell.sh host:port
- 从 Zookeeper 实例中:
- Stop Kafka server
- Delete the topic directory, on each broker (as defined in the
logs.dirs
andlog.dir
properties) withrm -rf
command - Connect to Zookeeper instance:
zookeeper-shell.sh host:port
- From within the Zookeeper instance:
- 使用以下方法列出主题:
ls/brokers/topics
- 使用以下命令从 ZooKeeper 中删除主题文件夹:
rmr/brokers/topics/yourtopic
- 退出 Zookeeper 实例 (Ctrl+C)
kafka-topics.sh --list --zookeeper host:port
这篇关于如何在apache kafka中删除主题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!