Manually Committing Offsets
通常,在使用 AckMode.MANUAL
或 AckMode.MANUAL_IMMEDIATE
时,必须按顺序确认确认,因为 Kafka 不会为每条记录维护状态,只会维护每个组/分区的一个已提交偏移量。从 2.8 版开始,您现在可以设置容器属性 asyncAcks
,这样就可以按任何顺序确认轮询返回的记录确认。侦听器容器会延迟确认超出顺序的提交,直到收到缺少的确认为止。系统会暂停消费者(不发送任何新记录),直到已经提交先前轮询的所有偏移量。
Normally, when using AckMode.MANUAL
or AckMode.MANUAL_IMMEDIATE
, the acknowledgments must be acknowledged in order, because Kafka does not maintain state for each record, only a committed offset for each group/partition.
Starting with version 2.8, you can now set the container property asyncAcks
, which allows the acknowledgments for records returned by the poll to be acknowledged in any order.
The listener container will defer the out-of-order commits until the missing acknowledgments are received.
The consumer will be paused (no new records delivered) until all the offsets for the previous poll have been committed.
虽然此功能允许应用程序异步处理记录,但应该明白,在发生故障后这会增加重复交付的可能性。
While this feature allows applications to process records asynchronously, it should be understood that it increases the possibility of duplicate deliveries after a failure.
当 asyncAcks
被激活时,不能在 Committing Offsets 中使用 nack()
(否定确认)。
When asyncAcks
is activated, it is not possible to use nack()
(negative acknowledgments) when Committing Offsets.