Description
In what version(s) of Spring for Apache Kafka are you seeing this issue?
3.3.1
Describe the bug
Intention was to process entire batch of messages as a single entity and retry it several times, then skip/recover entire batch if all retries exhausted.
Throwing BatchListenerFailedException is not applicable since
- it requires to specify failed record, while all records are considered failed and in case of passing first record - only it will be skipped, while all the rest from the batch are retried with the next poll operation to the Listener (as explained in Batch Listener when encountered a poison pill, records after that poison pill are moved to next poll. #3297).
- passing the last record from the batch - gives that only last message is retried instead of entire batch
Documentation suggests throwing non BatchListenerFailedException and it works only if backoff time is less than max.poll.interval. When delays are longer it causes rebalancing since FallbackBatchErrorHandler sleeps for backoff time between poll operations. Configuring ContainerPausingBackOffHandler as a backoff error handler in order to handle long delays does not have impact.
To Reproduce
Use batch Kafka listener which throws non-BatchListenerFailedException to retry entire batch of events.
Expected behavior
ContainerPausingBackOffHandler is applied when non-BatchListenerFailedException error is thrown.
Sample
Configuration of ErrorHandler:
final ExponentialBackOff backOff = new ExponentialBackOff(A, B);
backOff.setMaxInterval(C); // longer than max.poll.interval
backOff.setMaxElapsedTime(X);
return new DefaultErrorHandler(null, backOff, new ContainerPausingBackOffHandler(new ListenerContainerPauseService(null, taskScheduler));