问题
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?
回答1:
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
来源:https://stackoverflow.com/questions/49868789/delete-messages-from-a-topic-in-apache-kafka