簡體   English   中英

Kafkacat:如何刪除主題或其所有消息?

[英]Kafkacat: how to delete a topic or all its messages?

我正在尋找一種使用kafkacat刪除主題或其所有消息的方法。 是否可能或唯一的方法是通過此處列出的腳本?

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

根據手冊頁和github源代碼,kafkacat現階段沒有刪除主題功能。 所以唯一的方法是使用 kafka-topics 腳本。

源代碼

手冊頁

kafkacat 是 Apache Kafka 0.8 的通用非 JVM 生產者和消費者,可以將其視為 Kafka 的 netcat。

 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.

正如@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

是的,這是可能的。

但首先,您必須在所有代理上啟用主題刪除。 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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM