英文:
Spring Kafka MANUAL_IMMEDIATE Acknowledge Only Commits 1 Highest Offset of 1 Partition
问题
你好,Gary和Spring Kafka社区!
我在这里看到,当使用MANUAL_IMMEDIATE ack模式时,应该提交接收到记录的所有分区中的最高偏移量。这不是我正在经历的行为。
我正在使用@KafkaListener,并且有一个独立的对象和Acknowledgement对象作为我的两个方法参数。我需要在内存中累积消息,在达到一定阈值后发送它们,然后提交所有这些消息。我的计划是在发送它们之前只提交/确认我接收到的最后一条消息。
我尝试过保持一个Map<partitionId, Acknowledgement>,并在每次添加到该Map中。我观察到,当确认Map中的每个值(每个分区的最新确认)时,它也会提交所有之前的消息。
使用Spring Boot 2.7.8和Spring for Apache Kafka v2.8.11。
谢谢!
英文:
Hello Gary and the Spring Kafka community!
I saw here that when using MANUAL_IMMEDIATE ack mode, that it is supposed to commit the highest offset of all partitions for which records were received. This is not the behavior I am experiencing.
I am using @KafkaListener, and have an individual object and the Acknowledgement object as my 2 method parameters. I need to accumulate messages in memory, send them out after some threshold is met, and then commit all of said messages. My plan was to just commit/acknowledge the last message I receive before sending them out.
I did try keeping a Map<partitionId, Acknowledgement>, and adding to that every time. I do observe that when acknowledging every value in the map (the latest ack for each partition), it does commit all prior messages as well.
Using Spring Boot 2.7.8 w/ Spring for Apache Kafka v2.8.11.
Thanks!
答案1
得分: 1
不明白为什么这样认为?如果文档有误导之处,我想要进行修正。
除非您的监听器是批处理模式的监听器(从poll
中接收所有记录的List
或原始的ConsumerRecords
),您需要确认每个记录(或每个分区的最后一个记录)。在这种情况下,Acknowledgment
是针对整个批处理的。
英文:
>that it is supposed to commit the highest offset of all partitions for which records were received.
What makes you think that? If the documentation is misleading, I'd like to correct it.
You need to acknowledge each record (or the last one for each partition), unless your listener is a batch mode listener (receiving all the records from the poll in a List
or the raw ConsumerRecords
). In that case, the Acknowledgment
is for the entire batch.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论