Class FailedBatchProcessor
- java.lang.Object
-
- org.springframework.kafka.listener.KafkaExceptionLogLevelAware
-
- org.springframework.kafka.listener.ExceptionClassifier
-
- org.springframework.kafka.listener.FailedRecordProcessor
-
- org.springframework.kafka.listener.FailedBatchProcessor
-
- All Implemented Interfaces:
DeliveryAttemptAware
- Direct Known Subclasses:
DefaultErrorHandler
public abstract class FailedBatchProcessor extends FailedRecordProcessor
Subclass ofFailedRecordProcessorthat can process (and recover) a batch. If the listener throws aBatchListenerFailedException, the offsets prior to the failed record are committed and the remaining records have seeks performed. When the retries are exhausted, the failed record is sent to the recoverer instead of being included in the seeks. If other exceptions are thrown processing is delegated to the fallback handler.- Since:
- 2.8
- Author:
- Gary Russell, Francois Rosiere
-
-
Field Summary
-
Fields inherited from class org.springframework.kafka.listener.FailedRecordProcessor
logger
-
-
Constructor Summary
Constructors Constructor Description FailedBatchProcessor(java.util.function.BiConsumer<org.apache.kafka.clients.consumer.ConsumerRecord<?,?>,java.lang.Exception> recoverer, org.springframework.util.backoff.BackOff backOff, BackOffHandler backOffHandler, CommonErrorHandler fallbackHandler)Construct an instance with the provided properties.FailedBatchProcessor(java.util.function.BiConsumer<org.apache.kafka.clients.consumer.ConsumerRecord<?,?>,java.lang.Exception> recoverer, org.springframework.util.backoff.BackOff backOff, CommonErrorHandler fallbackHandler)Construct an instance with the provided properties.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected voiddoHandle(java.lang.Exception thrownException, org.apache.kafka.clients.consumer.ConsumerRecords<?,?> data, org.apache.kafka.clients.consumer.Consumer<?,?> consumer, MessageListenerContainer container, java.lang.Runnable invokeListener)protected CommonErrorHandlergetFallbackBatchHandler()Return the fallback batch error handler.protected <K,V>
org.apache.kafka.clients.consumer.ConsumerRecords<K,V>handle(java.lang.Exception thrownException, org.apache.kafka.clients.consumer.ConsumerRecords<?,?> data, org.apache.kafka.clients.consumer.Consumer<?,?> consumer, MessageListenerContainer container, java.lang.Runnable invokeListener)protected voidnotRetryable(java.util.stream.Stream<java.lang.Class<? extends java.lang.Exception>> notRetryable)Subclasses can override this to receive notification of configuration of not retryable exceptions.java.lang.BooleanremoveClassification(java.lang.Class<? extends java.lang.Exception> exceptionType)Remove an exception type from the configured list.voidsetClassifications(java.util.Map<java.lang.Class<? extends java.lang.Throwable>,java.lang.Boolean> classifications, boolean defaultValue)Set an exception classifications to determine whether the exception should cause a retry (until exhaustion) or not.voidsetLogLevel(KafkaException.Level logLevel)Set the level at which the exception thrown by this handler is logged.-
Methods inherited from class org.springframework.kafka.listener.FailedRecordProcessor
clearThreadState, deliveryAttempt, getFailureTracker, getRecoveryStrategy, getRecoveryStrategy, getRetryListeners, isCommitRecovered, isSeekAfterError, setBackOffFunction, setCommitRecovered, setResetStateOnExceptionChange, setResetStateOnRecoveryFailure, setRetryListeners, setSeekAfterError
-
Methods inherited from class org.springframework.kafka.listener.ExceptionClassifier
addNotRetryableExceptions, addRetryableExceptions, defaultFalse, defaultFatalExceptionsList, getClassifier, removeNotRetryableException
-
Methods inherited from class org.springframework.kafka.listener.KafkaExceptionLogLevelAware
getLogLevel
-
-
-
-
Constructor Detail
-
FailedBatchProcessor
public FailedBatchProcessor(@Nullable java.util.function.BiConsumer<org.apache.kafka.clients.consumer.ConsumerRecord<?,?>,java.lang.Exception> recoverer, org.springframework.util.backoff.BackOff backOff, CommonErrorHandler fallbackHandler)Construct an instance with the provided properties.- Parameters:
recoverer- the recoverer.backOff- the back off.fallbackHandler- the fall back handler.
-
FailedBatchProcessor
public FailedBatchProcessor(@Nullable java.util.function.BiConsumer<org.apache.kafka.clients.consumer.ConsumerRecord<?,?>,java.lang.Exception> recoverer, org.springframework.util.backoff.BackOff backOff, @Nullable BackOffHandler backOffHandler, CommonErrorHandler fallbackHandler)Construct an instance with the provided properties.- Parameters:
recoverer- the recoverer.backOff- the back off.backOffHandler- theBackOffHandlerfallbackHandler- the fall back handler.- Since:
- 2.9
-
-
Method Detail
-
setLogLevel
public void setLogLevel(KafkaException.Level logLevel)
Description copied from class:KafkaExceptionLogLevelAwareSet the level at which the exception thrown by this handler is logged.- Overrides:
setLogLevelin classKafkaExceptionLogLevelAware- Parameters:
logLevel- the level (default ERROR).
-
notRetryable
protected void notRetryable(java.util.stream.Stream<java.lang.Class<? extends java.lang.Exception>> notRetryable)
Description copied from class:ExceptionClassifierSubclasses can override this to receive notification of configuration of not retryable exceptions.- Overrides:
notRetryablein classExceptionClassifier- Parameters:
notRetryable- the not retryable exceptions.
-
setClassifications
public void setClassifications(java.util.Map<java.lang.Class<? extends java.lang.Throwable>,java.lang.Boolean> classifications, boolean defaultValue)Description copied from class:ExceptionClassifierSet an exception classifications to determine whether the exception should cause a retry (until exhaustion) or not. If not, we go straight to the recoverer. By default, the following exceptions will not be retried:DeserializationExceptionMessageConversionExceptionMethodArgumentResolutionExceptionNoSuchMethodExceptionClassCastException
- Overrides:
setClassificationsin classExceptionClassifier- Parameters:
classifications- the classifications.defaultValue- whether or not to retry non-matching exceptions.- See Also:
BinaryExceptionClassifier(Map, boolean),ExceptionClassifier.addNotRetryableExceptions(Class...)
-
removeClassification
@Nullable public java.lang.Boolean removeClassification(java.lang.Class<? extends java.lang.Exception> exceptionType)
Description copied from class:ExceptionClassifierRemove an exception type from the configured list. By default, the following exceptions will not be retried:DeserializationExceptionMessageConversionExceptionConversionExceptionMethodArgumentResolutionExceptionNoSuchMethodExceptionClassCastException
ExceptionClassifier.defaultFalse()has been called.- Overrides:
removeClassificationin classExceptionClassifier- Parameters:
exceptionType- the exception type.- Returns:
- the classification of the exception if removal was successful; null otherwise.
- See Also:
ExceptionClassifier.addNotRetryableExceptions(Class...),ExceptionClassifier.setClassifications(Map, boolean)
-
getFallbackBatchHandler
protected CommonErrorHandler getFallbackBatchHandler()
Return the fallback batch error handler.- Returns:
- the handler.
- Since:
- 2.8.8
-
doHandle
protected void doHandle(java.lang.Exception thrownException, org.apache.kafka.clients.consumer.ConsumerRecords<?,?> data, org.apache.kafka.clients.consumer.Consumer<?,?> consumer, MessageListenerContainer container, java.lang.Runnable invokeListener)
-
handle
protected <K,V> org.apache.kafka.clients.consumer.ConsumerRecords<K,V> handle(java.lang.Exception thrownException, org.apache.kafka.clients.consumer.ConsumerRecords<?,?> data, org.apache.kafka.clients.consumer.Consumer<?,?> consumer, MessageListenerContainer container, java.lang.Runnable invokeListener)
-
-