Kafkacat:如何删除主题或其所有消息?

时间:2019-04-19 09:57:25

标签: apache-kafka kafkacat

我正在寻找一种使用kafkacat删除主题或其所有消息的方法。 是否可以或唯一的方法是通过列出的here脚本?

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

3 个答案:

答案 0 :(得分:2)

根据手册页和github源代码,现阶段kafkacat中没有删除主题功能。因此,唯一的方法是使用kafka-topics脚本。

github source code

man page

  

kafkacat是Apache Kafka的通用非JVM生产者和使用者。   0.8,将其视为        卡夫卡的网猫。

 In producer mode ( -P ), kafkacat reads messages from stdin, delimited with a configurable
 delimeter and produces them to the provided Kafka cluster, topic and partition. In consumer
 mode ( -C ), kafkacat reads messages from a topic and partition and prints them to stdout
 using the configured message delimiter.

 If neither -P or -C are specified kafkacat attempts to figure out the mode automatically
 based on stdin/stdout tty types.

 kafkacat also features a metadata list mode ( -L ), to display the current state of the
 Kafka cluster and its topics and partitions.

答案 1 :(得分:0)

@Naween Banuka指出,您还可以使用zookeeper-shell.sh或zkCli.sh(在zookeeper / bin下找到)来执行此操作:

列出现有主题:./zookeeper-shell.sh localhost:2181 ls /brokers/topics

删除主题:./zookeeper-shell.sh localhost:2181 rmr /brokers/topics/yourtopic

答案 2 :(得分:-2)

是的,有可能。

但是首先,您必须在所有代理上启用主题删除。 将delete.topic.enable更改为true。 默认情况下,它是false(在server.properties文件中)

然后, 使用主题删除命令。

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

如果您想永久删除该主题, 您可以使用zookeeper delete命令。

  1. 列出现有主题:./zookeeper-shell.sh localhost:2181 ls /brokers/topics
  2. 删除主题:./zookeeper-shell.sh localhost:2181 rmr /brokers/topics/yourtopic
相关问题