Skip to content

Commit fc544cd

Browse files
garyrussellartembilan
authored andcommitted
GH-2128: Document Nack Sleep Time Limitations
See #2128 **cherry-pick to 2.9.x, 2.8.x**
1 parent 60c8f6c commit fc544cd

File tree

2 files changed

+10
-5
lines changed

2 files changed

+10
-5
lines changed

spring-kafka-docs/src/main/asciidoc/kafka.adoc

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1252,16 +1252,19 @@ NOTE: If you want to commit a partial batch, using `nack()`, When using transact
12521252

12531253
IMPORTANT: `nack()` can only be called on the consumer thread that invokes your listener.
12541254

1255-
With a record listener, when `nack()` is called, any pending offsets are committed, the remaing records from the last poll are discarded, and seeks are performed on their partitions so that the failed record and unprocessed records are redelivered on the next `poll()`.
1256-
The consumer thread can be paused before redelivery, by setting the `sleep` argument.
1255+
With a record listener, when `nack()` is called, any pending offsets are committed, the remaining records from the last poll are discarded, and seeks are performed on their partitions so that the failed record and unprocessed records are redelivered on the next `poll()`.
1256+
The consumer can be paused before redelivery, by setting the `sleep` argument.
12571257
This is similar functionality to throwing an exception when the container is configured with a `DefaultErrorHandler`.
12581258

12591259
When using a batch listener, you can specify the index within the batch where the failure occurred.
12601260
When `nack()` is called, offsets will be committed for records before the index and seeks are performed on the partitions for the failed and discarded records so that they will be redelivered on the next `poll()`.
12611261

12621262
See <<error-handlers>> for more information.
12631263

1264-
IMPORTANT: When using partition assignment via group management, it is important to ensure the `sleep` argument (plus the time spent processing records from the previous poll) is less than the consumer `max.poll.interval.ms` property.
1264+
IMPORTANT: The consumer is paused during the sleep so that we continue to poll the broker to keep the consumer alive.
1265+
The actual sleep time, and its resolution depends on the container's `maxPollInterval` which defaults to 5 seconds.
1266+
The minimum sleep time is equal to the `maxPollInterval` and all sleep times will be a multiple of it.
1267+
For small sleep times, consider reducing the container's `maxPollInterval`.
12651268

12661269
[[container-auto-startup]]
12671270
====== Listener Container Auto Startup

spring-kafka/src/main/java/org/springframework/kafka/support/Acknowledgment.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,8 @@ public interface Acknowledgment {
4343
* {@code sleep + time spent processing the previous messages from the poll} must be
4444
* less than the consumer {@code max.poll.interval.ms} property, to avoid a
4545
* rebalance.</b>
46-
* @param sleep the time to sleep.
46+
* @param sleep the time to sleep; the actual sleep time will be larger of this value
47+
* and the container's {@code maxPollInterval}, which defaults to 5 seconds.
4748
* @since 2.3
4849
*/
4950
default void nack(long sleep) {
@@ -60,7 +61,8 @@ default void nack(long sleep) {
6061
* {@code sleep + time spent processing the records before the index} must be less
6162
* than the consumer {@code max.poll.interval.ms} property, to avoid a rebalance.</b>
6263
* @param index the index of the failed record in the batch.
63-
* @param sleep the time to sleep.
64+
* @param sleep the time to sleep; the actual sleep time will be larger of this value
65+
* and the container's {@code maxPollInterval}, which defaults to 5 seconds.
6466
* @since 2.3
6567
*/
6668
default void nack(int index, long sleep) {

0 commit comments

Comments
 (0)