Search code examples
apache-kafkaapache-zookeeperkafka-producer-api

Delete all messages from Kafka topic


I have seen similar questions related to this, But didn't find the correct answer. I just want to delete messages from Kafka topic instead of changing the retention timeout. I have installed kafka_2.11-0.8.2.1 and running it on windows using bat files. I want to know if I can delete all the messages published in a topic without deleting the entire topic.


Solution

  • You cannot do that with 0.8.2. Starting from 0.11.0 you get a kafka-delete-records.sh tool for doing that. Starting from 1.1 you even have a Java AdminClient API with deleteRecords methods for doing this programmtically.