从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屋!