简体   繁体   English

Java Spring引导kafka从带有偏移量的主题中删除消息

[英]Java Spring boot kafka delete message from topic with offset

I am trying to create an spring boot app(java) that that must be able to delete a message from a kafka topic by giving its offset number and partition.我正在尝试创建一个 Spring Boot 应用程序(java),它必须能够通过提供偏移号和分区来从 kafka 主题中删除消息。 I have been I have been researching the java or spring boot package classes that can do this, but I only have found something like this: Delete Messages from a Topic in Apache Kafka there is a java kafka client that have a method to delete ALL messages BEFORE an offset, but I just one to delete one.我一直在研究可以做到这一点的 java 或 spring boot 包类,但我只发现了这样的东西: 从 Apache Kafka 中的主题删除消息有一个 java kafka 客户端,它有一个方法来删除所有消息BEFORE 一个偏移量,但我只是一个删除一个。 It is that possible?这可能吗?

thanks in advance提前致谢

If you only have the offset number and partition, and you could just delete the record at that offset, you can't guarantee that all consumers will have an eventually-consistent view, so that's why it's not a standard operation.如果您只有偏移量和分区,并且您可以只删除该偏移量处的记录,则无法保证所有消费者都具有最终一致的视图,因此这就是为什么它不是标准操作的原因。

The suggestion: write a new record with the same key and a null body can serve as an event to tell all consumers the record is deleted.建议:用相同的键写一条新记录,空体可以作为一个事件告诉所有消费者该记录已被删除。

The record with the null body will stay in the topic as configured in the delete retention time.带有空正文的记录将保留在删除保留时间中配置的主题中。 This is usually longer than the normal retention time, to make sure consumers have enough time to delete obsolete records.这通常比正常保留时间长,以确保消费者有足够的时间删除过时的记录。 After the delete retention time expires, both the original record and the null record will be removed by log compaction.删除保留时间到期后,原始记录和空记录都将通过日志压缩删除。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM