Delete Messages from a Topic in Apache Kafka

≡放荡痞女 提交于 2021-02-10 03:26:35

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!