Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Delete Messages from a Topic in Apache Kafka

So I am new to working with Apache Kafka and I am trying to create a simple app so I can try to understand the API better. I know this question has been asked a lot here, but how can I clear out the messages/records that are stored on a topic?

Most of the answers I have seen say to change the message retention time or to delete & recreate the topic. Neither of these are options for me as I do not have access to the server.properties file. I am not running Kafka locally, it is hosted on a server. Is there a way to do do it in Java code maybe or something?

like image 263
Dani Avatar asked Mar 06 '23 09:03

Dani


1 Answers

If you are searching for a way to delete messages selectively, the new AdminClient API (usable from Java code) provides the following deleteRecords method :

https://kafka.apache.org/11/javadoc/org/apache/kafka/clients/admin/AdminClient.html

like image 121
ppatierno Avatar answered Mar 17 '23 18:03

ppatierno