Spring Kafka MANUAL_IMMEDIATE Acknowledge Only Commits 1 Highest Offset of 1 Partition

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

Spring Kafka MANUAL_IMMEDIATE Acknowledge Only Commits 1 Highest Offset of 1 Partition

问题

你好,Gary和Spring Kafka社区! Spring Kafka MANUAL_IMMEDIATE Acknowledge Only Commits 1 Highest Offset of 1 Partition

我在这里看到,当使用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! Spring Kafka MANUAL_IMMEDIATE Acknowledge Only Commits 1 Highest Offset of 1 Partition

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.

huangapple
  • 本文由 发表于 2023年2月24日 10:14:48
  • 转载请务必保留本文链接:https://go.coder-hub.com/75552059.html
匿名

发表评论

匿名网友

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

确定