In AckMode MANUAL_IMMEDIATE, is acknowledgment.acknowledge() optional ? #2519
-
Consider the below 2 scenarios,
While I see acknowledgment.nack() working fine, from the above scenarios it looks like we can skip using acknowledgment.acknowledge() as it not contributing anything. Is this a bug or am I missing something here ? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 2 replies
-
It is not "optional", calling acknowledge() commits the offset; if there are no more records and you restart the consumer, the record will not be redelivered. Conversely, if you exit without acknowledging, the offset won't be committed and, if there are no records after this one, and you restart the consumer, the record will be redelivered. Kafka maintains two pointers, the current position and the committed offset. Each poll returns record(s) from the current position. When a consumer starts, the current position is set to the committed offset (if there is one). It might "appear" to be optional because, if there are more records (successfully processed) after the one you failed to acknowledge, then their offsets will be committed (and by definition, their offsets will be after the one you failed to commit). |
Beta Was this translation helpful? Give feedback.
It is not "optional", calling acknowledge() commits the offset; if there are no more records and you restart the consumer, the record will not be redelivered.
Conversely, if you exit without acknowledging, the offset won't be committed and, if there are no records after this one, and you restart the consumer, the record will be redelivered.
Kafka maintains two pointers, the current position and the committed offset. Each poll returns record(s) from the current position. When a consumer starts, the current position is set to the committed offset (if there is one).
It might "appear" to be optional because, if there are more records (successfully processed) after the one you failed to acknow…