从 Apache Kafka 中的主题中删除消息 [英] Delete Messages from a Topic in Apache Kafka
问题描述
所以我是 Apache Kafka 的新手,我正在尝试创建一个简单的应用程序,以便我可以尝试更好地理解 API.我知道这里已经问了很多这个问题,但是如何清除存储在主题上的消息/记录?
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?
我看到的大多数答案都说要更改消息保留时间或删除 &重新创建主题.这些都不适合我,因为我无权访问 server.properties 文件.我没有在本地运行 Kafka,它托管在服务器上.有没有办法在Java代码中做到这一点?
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?
推荐答案
如果您正在寻找一种选择性删除消息的方法,新的 AdminClient API(可从 Java 代码使用)提供以下 deleteRecords
方法:
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
这篇关于从 Apache Kafka 中的主题中删除消息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!