Kafkacat: how to delete a topic or all its messages?
Asked Answered
S

3

8

I am looking for a way to delete a topic or all its messages using kafkacat. Is it possible or the only way is through the script listed here?

bin/kafka-topics.sh --zookeeper localhost:2181 --delete --topic mytopic
Stereotypy answered 19/4, 2019 at 9:57 Comment(0)
T
5

There is no delete topic feature at this stage in kafkacat according to man page and github source code. So the only way is to use kafka-topics script.

github source code

man page

kafkacat is a generic non-JVM producer and consumer for Apache Kafka 0.8, think of it as a netcat for Kafka.

 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.
Tussah answered 19/4, 2019 at 10:16 Comment(0)
P
0

As @Naween Banuka pointed out, you can also use zookeeper-shell.sh or zkCli.sh (found under zookeeper/bin) to do this:

List the existing topics : ./zookeeper-shell.sh localhost:2181 ls /brokers/topics

Remove Topic : ./zookeeper-shell.sh localhost:2181 rmr /brokers/topics/yourtopic

Proud answered 4/9, 2020 at 22:6 Comment(0)
F
-5

Yes, It's possible.

But first, You have to enable topic deletion on all brokers. change delete.topic.enable to true. By default, it's false (In server.properties file)

Then, Use topic delete command.

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

If you want to delete that topic permanently, You can use the zookeeper delete command.

  1. List the existing topics : ./zookeeper-shell.sh localhost:2181 ls /brokers/topics
  2. Remove Topic : ./zookeeper-shell.sh localhost:2181 rmr /brokers/topics/yourtopic
Festatus answered 19/4, 2019 at 10:33 Comment(2)
I just want to show why you got minuses. The question is "Could I delete topic another way than kafka-topics.sh?". And your answer is "Yes, it's kafka-topics.sh".Supernational
But you guys missed the second part zookeeper-shell.shFestatus

© 2022 - 2024 — McMap. All rights reserved.