To delete all the messages from a Kafka topic, you need to change the retention time of that topic the default retention time of Kafka topic is 168 hours, i.e. 7 days. In this case, you have to change the retention time to 1 second, after which the messages from the topic will be deleted. After changing the retention time, you can go ahead and change the retention time of the topic back to 168 hours.
You can change the retention of the topic by using the following command:
kafka-topics.sh --zookeeper localhost:2181 --alter --topic topic1 --config retention.ms=1000
If you wish to know about Kafka visit this Kafka Tutorial and Kafka Interview Questions.