public class RetryingBatchErrorHandler extends KafkaExceptionLogLevelAware implements ListenerInvokingBatchErrorHandler
BackOff. The consumer is paused/polled/resumed before each retry in order to
avoid a rebalance. If/when retries are exhausted, the provided
ConsumerRecordRecoverer 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.| Constructor and Description |
|---|
RetryingBatchErrorHandler()
Construct an instance with a default
FixedBackOff (unlimited attempts with
a 5 second back off). |
RetryingBatchErrorHandler(org.springframework.util.backoff.BackOff backOff,
ConsumerRecordRecoverer recoverer)
Construct an instance with the provided
BackOff and
ConsumerRecordRecoverer. |
| Modifier and Type | Method and 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).
|
getLogLevel, setLogLevelclone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waithandlehandlehandleclearThreadStatepublic RetryingBatchErrorHandler()
FixedBackOff (unlimited attempts with
a 5 second back off).public RetryingBatchErrorHandler(org.springframework.util.backoff.BackOff backOff,
@Nullable
ConsumerRecordRecoverer recoverer)
BackOff and
ConsumerRecordRecoverer. If the recoverer is null, the discarded
records (topic-partition@offset) will be logged.backOff - the back off.recoverer - the recoverer.public boolean isAckAfterHandle()
GenericErrorHandlerisAckAfterHandle in interface GenericErrorHandler<org.apache.kafka.clients.consumer.ConsumerRecords<?,?>>public void setAckAfterHandle(boolean ackAfterHandle)
GenericErrorHandlersetAckAfterHandle in interface GenericErrorHandler<org.apache.kafka.clients.consumer.ConsumerRecords<?,?>>ackAfterHandle - false to not commit.public 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)
ContainerAwareBatchErrorHandlerhandle in interface BatchErrorHandlerhandle in interface ContainerAwareBatchErrorHandlerhandle in interface ListenerInvokingBatchErrorHandlerthrownException - the exception.records - the consumer records.consumer - the consumer.container - the container.invokeListener - a callback to re-invoke the listener.