[英]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 命令。
./zookeeper-shell.sh localhost:2181 ls /brokers/topics
./zookeeper-shell.sh localhost:2181 rmr /brokers/topics/yourtopic
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.