Class RetryingBatchErrorHandler
- java.lang.Object
-
- org.springframework.kafka.listener.KafkaExceptionLogLevelAware
-
- org.springframework.kafka.listener.RetryingBatchErrorHandler
-
- All Implemented Interfaces:
BatchErrorHandler
,ConsumerAwareBatchErrorHandler
,ContainerAwareBatchErrorHandler
,GenericErrorHandler<org.apache.kafka.clients.consumer.ConsumerRecords<?,?>>
,ListenerInvokingBatchErrorHandler
public class RetryingBatchErrorHandler extends KafkaExceptionLogLevelAware implements ListenerInvokingBatchErrorHandler
A batch error handler that invokes the listener according to the suppliedBackOff
. The consumer is paused/polled/resumed before each retry in order to avoid a rebalance. If/when retries are exhausted, the providedConsumerRecordRecoverer
is invoked for each record in the batch. If the recoverer throws an exception, or the thread is interrupted while sleeping, seeks are performed so that the batch will be redelivered on the next poll.- Since:
- 2.3.7
- Author:
- Gary Russell
-
-
Constructor Summary
Constructors Constructor Description RetryingBatchErrorHandler()
Construct an instance with a defaultFixedBackOff
(unlimited attempts with a 5 second back off).RetryingBatchErrorHandler(org.springframework.util.backoff.BackOff backOff, ConsumerRecordRecoverer recoverer)
Construct an instance with the providedBackOff
andConsumerRecordRecoverer
.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
handle(java.lang.Exception thrownException, org.apache.kafka.clients.consumer.ConsumerRecords<?,?> records, org.apache.kafka.clients.consumer.Consumer<?,?> consumer, MessageListenerContainer container, java.lang.Runnable invokeListener)
Handle the exception.boolean
isAckAfterHandle()
Return true if the offset should be committed for a handled error (no exception thrown).void
setAckAfterHandle(boolean ackAfterHandle)
Set to false to prevent the container from committing the offset of a recovered record (when the error handler does not itself throw an exception).-
Methods inherited from class org.springframework.kafka.listener.KafkaExceptionLogLevelAware
getLogLevel, setLogLevel
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface org.springframework.kafka.listener.ConsumerAwareBatchErrorHandler
handle
-
Methods inherited from interface org.springframework.kafka.listener.ContainerAwareBatchErrorHandler
handle
-
Methods inherited from interface org.springframework.kafka.listener.GenericErrorHandler
clearThreadState
-
Methods inherited from interface org.springframework.kafka.listener.ListenerInvokingBatchErrorHandler
handle
-
-
-
-
Constructor Detail
-
RetryingBatchErrorHandler
public RetryingBatchErrorHandler()
Construct an instance with a defaultFixedBackOff
(unlimited attempts with a 5 second back off).
-
RetryingBatchErrorHandler
public RetryingBatchErrorHandler(org.springframework.util.backoff.BackOff backOff, @Nullable ConsumerRecordRecoverer recoverer)
Construct an instance with the providedBackOff
andConsumerRecordRecoverer
. If the recoverer isnull
, the discarded records (topic-partition@offset) will be logged.- Parameters:
backOff
- the back off.recoverer
- the recoverer.
-
-
Method Detail
-
isAckAfterHandle
public boolean isAckAfterHandle()
Description copied from interface:GenericErrorHandler
Return true if the offset should be committed for a handled error (no exception thrown).- Specified by:
isAckAfterHandle
in interfaceGenericErrorHandler<org.apache.kafka.clients.consumer.ConsumerRecords<?,?>>
- Returns:
- true to commit.
-
setAckAfterHandle
public void setAckAfterHandle(boolean ackAfterHandle)
Description copied from interface:GenericErrorHandler
Set to false to prevent the container from committing the offset of a recovered record (when the error handler does not itself throw an exception).- Specified by:
setAckAfterHandle
in interfaceGenericErrorHandler<org.apache.kafka.clients.consumer.ConsumerRecords<?,?>>
- Parameters:
ackAfterHandle
- false to not commit.
-
handle
public void handle(java.lang.Exception thrownException, @Nullable org.apache.kafka.clients.consumer.ConsumerRecords<?,?> records, org.apache.kafka.clients.consumer.Consumer<?,?> consumer, MessageListenerContainer container, java.lang.Runnable invokeListener)
Description copied from interface:ContainerAwareBatchErrorHandler
Handle the exception.- Specified by:
handle
in interfaceBatchErrorHandler
- Specified by:
handle
in interfaceContainerAwareBatchErrorHandler
- Specified by:
handle
in interfaceListenerInvokingBatchErrorHandler
- Parameters:
thrownException
- the exception.records
- the consumer records.consumer
- the consumer.container
- the container.invokeListener
- a callback to re-invoke the listener.
-
-