Class SeekToCurrentErrorHandler
- java.lang.Object
-
- org.springframework.kafka.listener.KafkaExceptionLogLevelAware
-
- org.springframework.kafka.listener.FailedRecordProcessor
-
- org.springframework.kafka.listener.SeekToCurrentErrorHandler
-
- All Implemented Interfaces:
ConsumerAwareErrorHandler
,ContainerAwareErrorHandler
,DeliveryAttemptAware
,ErrorHandler
,GenericErrorHandler<org.apache.kafka.clients.consumer.ConsumerRecord<?,?>>
,RemainingRecordsErrorHandler
public class SeekToCurrentErrorHandler extends FailedRecordProcessor implements ContainerAwareErrorHandler
An error handler that seeks to the current offset for each topic in the remaining records. Used to rewind partitions after a message failure so that it can be replayed.- Since:
- 2.0.1
- Author:
- Gary Russell, Artem Bilan
-
-
Field Summary
-
Fields inherited from class org.springframework.kafka.listener.FailedRecordProcessor
logger
-
-
Constructor Summary
Constructors Constructor Description SeekToCurrentErrorHandler()
Construct an instance with the default recoverer which simply logs the record after 10 (maxFailures) have occurred for a topic/partition/offset, with the default back off (9 retries, no delay).SeekToCurrentErrorHandler(java.util.function.BiConsumer<org.apache.kafka.clients.consumer.ConsumerRecord<?,?>,java.lang.Exception> recoverer)
Construct an instance with the provided recoverer which will be called after 10 (maxFailures) have occurred for a topic/partition/offset.SeekToCurrentErrorHandler(java.util.function.BiConsumer<org.apache.kafka.clients.consumer.ConsumerRecord<?,?>,java.lang.Exception> recoverer, org.springframework.util.backoff.BackOff backOff)
Construct an instance with the provided recoverer which will be called after the backOff returns STOP for a topic/partition/offset.SeekToCurrentErrorHandler(org.springframework.util.backoff.BackOff backOff)
Construct an instance with the default recoverer which simply logs the record after the backOff returns STOP for a topic/partition/offset.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
handle(java.lang.Exception thrownException, java.util.List<org.apache.kafka.clients.consumer.ConsumerRecord<?,?>> records, org.apache.kafka.clients.consumer.Consumer<?,?> consumer, MessageListenerContainer container)
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).void
setCommitRecovered(boolean commitRecovered)
Set to true to commit the offset for a recovered record.-
Methods inherited from class org.springframework.kafka.listener.FailedRecordProcessor
addNotRetryableExceptions, clearThreadState, deliveryAttempt, getClassifier, getRecoveryStrategy, getSkipPredicate, isCommitRecovered, removeNotRetryableException, setBackOffFunction, setClassifications, setResetStateOnExceptionChange, setResetStateOnRecoveryFailure, setRetryListeners
-
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.ConsumerAwareErrorHandler
handle
-
Methods inherited from interface org.springframework.kafka.listener.ContainerAwareErrorHandler
handle
-
Methods inherited from interface org.springframework.kafka.listener.GenericErrorHandler
clearThreadState
-
Methods inherited from interface org.springframework.kafka.listener.RemainingRecordsErrorHandler
handle
-
-
-
-
Constructor Detail
-
SeekToCurrentErrorHandler
public SeekToCurrentErrorHandler()
Construct an instance with the default recoverer which simply logs the record after 10 (maxFailures) have occurred for a topic/partition/offset, with the default back off (9 retries, no delay).- Since:
- 2.2
-
SeekToCurrentErrorHandler
public SeekToCurrentErrorHandler(org.springframework.util.backoff.BackOff backOff)
Construct an instance with the default recoverer which simply logs the record after the backOff returns STOP for a topic/partition/offset.- Parameters:
backOff
- theBackOff
.- Since:
- 2.3
-
SeekToCurrentErrorHandler
public SeekToCurrentErrorHandler(java.util.function.BiConsumer<org.apache.kafka.clients.consumer.ConsumerRecord<?,?>,java.lang.Exception> recoverer)
Construct an instance with the provided recoverer which will be called after 10 (maxFailures) have occurred for a topic/partition/offset.- Parameters:
recoverer
- the recoverer.- Since:
- 2.2
-
SeekToCurrentErrorHandler
public SeekToCurrentErrorHandler(@Nullable java.util.function.BiConsumer<org.apache.kafka.clients.consumer.ConsumerRecord<?,?>,java.lang.Exception> recoverer, org.springframework.util.backoff.BackOff backOff)
Construct an instance with the provided recoverer which will be called after the backOff returns STOP for a topic/partition/offset.- Parameters:
recoverer
- the recoverer; if null, the default (logging) recoverer is used.backOff
- theBackOff
.- Since:
- 2.3
-
-
Method Detail
-
setCommitRecovered
public void setCommitRecovered(boolean commitRecovered)
Set to true to commit the offset for a recovered record. The container must be configured withContainerProperties.AckMode.MANUAL_IMMEDIATE
. Whether or not the commit is sync or async depends on the container's syncCommits property.- Overrides:
setCommitRecovered
in classFailedRecordProcessor
- Parameters:
commitRecovered
- true to commit.
-
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.ConsumerRecord<?,?>>
- 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.ConsumerRecord<?,?>>
- Parameters:
ackAfterHandle
- false to not commit.
-
handle
public void handle(java.lang.Exception thrownException, @Nullable java.util.List<org.apache.kafka.clients.consumer.ConsumerRecord<?,?>> records, org.apache.kafka.clients.consumer.Consumer<?,?> consumer, MessageListenerContainer container)
Description copied from interface:ErrorHandler
Handle the exception.- Specified by:
handle
in interfaceConsumerAwareErrorHandler
- Specified by:
handle
in interfaceContainerAwareErrorHandler
- Specified by:
handle
in interfaceErrorHandler
- Specified by:
handle
in interfaceRemainingRecordsErrorHandler
- Parameters:
thrownException
- the exception.records
- the remaining records including the one that failed.consumer
- the consumer.container
- the container.
-
-