Java Spring Boot中从Kafka主题中按偏移量删除消息

huangapple go评论106阅读模式
英文:

Java Spring boot kafka delete message from topic with offset

问题

我正在尝试创建一个Spring Boot应用程序(Java),必须能够通过提供其偏移量编号和分区来从Kafka主题中删除消息。
我一直在研究可以实现此功能的Java或Spring Boot软件包类,但我只找到了类似这样的内容:
https://stackoverflow.com/questions/49868789/delete-messages-from-a-topic-in-apache-kafka
有一个Java Kafka客户端,其中有一个方法可以删除偏移量之前的所有消息,但我只想删除一个消息。
这种操作是否可行?

提前致谢。

英文:

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.
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:
https://stackoverflow.com/questions/49868789/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.
It is that possible?

thanks in advance

答案1

得分: 2

如果您仅具有偏移量编号和分区,并且只能删除该偏移量处的记录,那么无法保证所有消费者会获得最终一致的视图,因此这就不是标准操作。

建议:编写一个具有相同键但空主体的新记录,可以作为向所有消费者通知记录已删除的事件。

具有空主体的记录将根据删除保留时间保留在主题中。这通常比正常保留时间长,以确保消费者有足够的时间来删除过时的记录。在删除保留时间过期后,原始记录和空记录都将被日志压实删除。

英文:

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.

huangapple
  • 本文由 发表于 2020年9月8日 19:36:58
  • 转载请务必保留本文链接:https://go.coder-hub.com/63793085.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定