Class FailedRecordProcessor
- java.lang.Object
-
- org.springframework.kafka.listener.KafkaExceptionLogLevelAware
-
- org.springframework.kafka.listener.ExceptionClassifier
-
- org.springframework.kafka.listener.FailedRecordProcessor
-
- All Implemented Interfaces:
DeliveryAttemptAware
- Direct Known Subclasses:
DefaultAfterRollbackProcessor
,FailedBatchProcessor
,SeekToCurrentErrorHandler
public abstract class FailedRecordProcessor extends ExceptionClassifier implements DeliveryAttemptAware
Common super class for classes that deal with failing to consume a consumer record.- Since:
- 2.3.1
- Author:
- Gary Russell
-
-
Field Summary
Fields Modifier and Type Field Description protected org.springframework.core.log.LogAccessor
logger
-
Constructor Summary
Constructors Modifier Constructor Description protected
FailedRecordProcessor(java.util.function.BiConsumer<org.apache.kafka.clients.consumer.ConsumerRecord<?,?>,java.lang.Exception> recoverer, org.springframework.util.backoff.BackOff backOff)
-
Method Summary
All Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description void
clearThreadState()
int
deliveryAttempt(TopicPartitionOffset topicPartitionOffset)
Return the next delivery attempt for the topic/partition/offset.protected RecoveryStrategy
getRecoveryStrategy(java.util.List<org.apache.kafka.clients.consumer.ConsumerRecord<?,?>> records, java.lang.Exception thrownException)
Return aRecoveryStrategy
to call to determine whether the first record in the list should be skipped.protected RecoveryStrategy
getRecoveryStrategy(java.util.List<org.apache.kafka.clients.consumer.ConsumerRecord<?,?>> records, org.apache.kafka.clients.consumer.Consumer<?,?> recoveryConsumer, java.lang.Exception thrownException)
Return aRecoveryStrategy
to call to determine whether the first record in the list should be skipped.protected java.util.function.BiPredicate<org.apache.kafka.clients.consumer.ConsumerRecord<?,?>,java.lang.Exception>
getSkipPredicate(java.util.List<org.apache.kafka.clients.consumer.ConsumerRecord<?,?>> records, java.lang.Exception thrownException)
Deprecated.in favor ofgetRecoveryStrategy(List, Exception)
.protected boolean
isCommitRecovered()
Whether the offset for a recovered record should be committed.void
setBackOffFunction(java.util.function.BiFunction<org.apache.kafka.clients.consumer.ConsumerRecord<?,?>,java.lang.Exception,org.springframework.util.backoff.BackOff> backOffFunction)
Set a function to dynamically determine theBackOff
to use, based on the consumer record and/or exception.void
setCommitRecovered(boolean commitRecovered)
Set to true to commit the offset for a recovered record.void
setResetStateOnExceptionChange(boolean resetStateOnExceptionChange)
Set to true to reset the retryBackOff
if the exception is a different type to the previous failure for the same record.void
setResetStateOnRecoveryFailure(boolean resetStateOnRecoveryFailure)
Set to false to immediately attempt to recover on the next attempt instead of repeating the BackOff cycle when recovery fails.void
setRetryListeners(RetryListener... listeners)
Set one or moreRetryListener
to receive notifications of retries and recovery.-
Methods inherited from class org.springframework.kafka.listener.ExceptionClassifier
addNotRetryableExceptions, addRetryableExceptions, defaultFalse, getClassifier, removeClassification, removeNotRetryableException, setClassifications
-
Methods inherited from class org.springframework.kafka.listener.KafkaExceptionLogLevelAware
getLogLevel, setLogLevel
-
-
-
-
Method Detail
-
isCommitRecovered
protected boolean isCommitRecovered()
Whether the offset for a recovered record should be committed.- Returns:
- true to commit recovered record offsets.
-
setCommitRecovered
public void setCommitRecovered(boolean commitRecovered)
Set to true to commit the offset for a recovered record.- Parameters:
commitRecovered
- true to commit.
-
setBackOffFunction
public void setBackOffFunction(java.util.function.BiFunction<org.apache.kafka.clients.consumer.ConsumerRecord<?,?>,java.lang.Exception,org.springframework.util.backoff.BackOff> backOffFunction)
Set a function to dynamically determine theBackOff
to use, based on the consumer record and/or exception. If null is returned, the default BackOff will be used.- Parameters:
backOffFunction
- the function.- Since:
- 2.6
-
setResetStateOnRecoveryFailure
public void setResetStateOnRecoveryFailure(boolean resetStateOnRecoveryFailure)
Set to false to immediately attempt to recover on the next attempt instead of repeating the BackOff cycle when recovery fails.- Parameters:
resetStateOnRecoveryFailure
- false to retain state.- Since:
- 2.5.5
-
setResetStateOnExceptionChange
public void setResetStateOnExceptionChange(boolean resetStateOnExceptionChange)
Set to true to reset the retryBackOff
if the exception is a different type to the previous failure for the same record. ThebackOffFunction
, if provided, will be called to get theBackOff
to use for the new exception; otherwise, the configuredBackOff
will be used.- Parameters:
resetStateOnExceptionChange
- true to reset.- Since:
- 2.6.3
-
setRetryListeners
public void setRetryListeners(RetryListener... listeners)
Set one or moreRetryListener
to receive notifications of retries and recovery.- Parameters:
listeners
- the listeners.- Since:
- 2.7
-
deliveryAttempt
public int deliveryAttempt(TopicPartitionOffset topicPartitionOffset)
Description copied from interface:DeliveryAttemptAware
Return the next delivery attempt for the topic/partition/offset.- Specified by:
deliveryAttempt
in interfaceDeliveryAttemptAware
- Parameters:
topicPartitionOffset
- the topic/partition/offset.- Returns:
- the next delivery attempt.
-
getSkipPredicate
@Deprecated protected java.util.function.BiPredicate<org.apache.kafka.clients.consumer.ConsumerRecord<?,?>,java.lang.Exception> getSkipPredicate(java.util.List<org.apache.kafka.clients.consumer.ConsumerRecord<?,?>> records, java.lang.Exception thrownException)
Deprecated.in favor ofgetRecoveryStrategy(List, Exception)
.Return aBiPredicate
to call to determine whether the first record in the list should be skipped.- Parameters:
records
- the records.thrownException
- the exception.- Returns:
- the
BiPredicate
.
-
getRecoveryStrategy
protected RecoveryStrategy getRecoveryStrategy(java.util.List<org.apache.kafka.clients.consumer.ConsumerRecord<?,?>> records, java.lang.Exception thrownException)
Return aRecoveryStrategy
to call to determine whether the first record in the list should be skipped.- Parameters:
records
- the records.thrownException
- the exception.- Returns:
- the
RecoveryStrategy
. - Since:
- 2.7
-
getRecoveryStrategy
protected RecoveryStrategy getRecoveryStrategy(java.util.List<org.apache.kafka.clients.consumer.ConsumerRecord<?,?>> records, @Nullable org.apache.kafka.clients.consumer.Consumer<?,?> recoveryConsumer, java.lang.Exception thrownException)
Return aRecoveryStrategy
to call to determine whether the first record in the list should be skipped.- Parameters:
records
- the records.recoveryConsumer
- the consumer.thrownException
- the exception.- Returns:
- the
RecoveryStrategy
. - Since:
- 2.8.4
-
clearThreadState
public void clearThreadState()
-
-