如何删除apache kafka中的主题 [英] How to Delete a topic in apache kafka

查看:656
本文介绍了如何删除apache kafka中的主题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要删除kafka-0.8.2.2.3中的一个主题。我已经使用下面的命令来删除主题:

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

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

  bin / kafka- topics.sh --list --zookeeper localhost:2181 
DummyTopic - 标记为删除

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

 执行时出错主题命令主题DummyTopic已经存在。 
kafka.common.TopicExistsException:主题DummyTopic已经存在。
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)

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

解决方案

自0.8.2.x版本以来,已经支持删除主题。您必须首先在所有经纪商上启用删除主题(设置 delete.topic.enable 为true)。



这个手动删除主题的分步过程


  1. 停止 Kafka 服务器

  2. 使用 rm -rf 命令

  3. 连接到 Zookeeper 实例: zookeeper-shell.sh host:port

  4. ls / brokers / topics


  5. 使用 rmr / brokers / topics / yourtopic

  6. 从ZooKeeper删除主题文件夹重新启动 Kafka 服务器

  7. 使用以下命令确认它是否被删除:
    kafka-topics.sh --list --zookeeper host:port


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

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.

解决方案

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.

Follow this step by step process for manual deletion of topics

  1. Stop Kafka server
  2. Delete the topic directory with rm -rf command
  3. Connect to Zookeeper instance: zookeeper-shell.sh host:port

  4. ls /brokers/topics

  5. Remove the topic folder from ZooKeeper using rmr /brokers/topics/yourtopic
  6. Restart Kafka server
  7. Confirm if it was deleted or not by using this command kafka-topics.sh --list --zookeeper host:port

这篇关于如何删除apache kafka中的主题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆