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
Subclass of
FailedRecordProcessor
that can process (and recover) a batch. If
the listener throws a BatchListenerFailedException
, 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
-
Field Summary
Fields inherited from class org.springframework.kafka.listener.FailedRecordProcessor
logger
-
Constructor Summary
ConstructorDescriptionFailedBatchProcessor
(BiConsumer<org.apache.kafka.clients.consumer.ConsumerRecord<?, ?>, Exception> recoverer, org.springframework.util.backoff.BackOff backOff, BackOffHandler backOffHandler, CommonErrorHandler fallbackHandler) Construct an instance with the provided properties.FailedBatchProcessor
(BiConsumer<org.apache.kafka.clients.consumer.ConsumerRecord<?, ?>, Exception> recoverer, org.springframework.util.backoff.BackOff backOff, CommonErrorHandler fallbackHandler) Construct an instance with the provided properties. -
Method Summary
Modifier and TypeMethodDescriptionprotected void
doHandle
(Exception thrownException, org.apache.kafka.clients.consumer.ConsumerRecords<?, ?> data, org.apache.kafka.clients.consumer.Consumer<?, ?> consumer, MessageListenerContainer container, Runnable invokeListener) protected CommonErrorHandler
Return the fallback batch error handler.protected <K,
V> org.apache.kafka.clients.consumer.ConsumerRecords<K, V> handle
(Exception thrownException, org.apache.kafka.clients.consumer.ConsumerRecords<?, ?> data, org.apache.kafka.clients.consumer.Consumer<?, ?> consumer, MessageListenerContainer container, Runnable invokeListener) protected void
notRetryable
(Stream<Class<? extends Exception>> notRetryable) Subclasses can override this to receive notification of configuration of not retryable exceptions.removeClassification
(Class<? extends Exception> exceptionType) Remove an exception type from the configured list.void
setClassifications
(Map<Class<? extends Throwable>, Boolean> classifications, boolean defaultValue) Set an exception classifications to determine whether the exception should cause a retry (until exhaustion) or not.void
setLogLevel
(KafkaException.Level logLevel) Set the level at which the exception thrown by this handler is logged.void
setReclassifyOnExceptionChange
(boolean reclassifyOnExceptionChange) Set to false to not reclassify the exception if different from the previous failure.void
setRetryListeners
(RetryListener... listeners) Set one or moreRetryListener
to receive notifications of retries and recovery.Methods inherited from class org.springframework.kafka.listener.FailedRecordProcessor
clearThreadState, deliveryAttempt, getFailureTracker, getRetryListeners, isCommitRecovered, isSeekAfterError, setBackOffFunction, setCommitRecovered, setResetStateOnExceptionChange, setResetStateOnRecoveryFailure, setSeekAfterError
Methods inherited from class org.springframework.kafka.listener.ExceptionClassifier
addNotRetryableExceptions, addRetryableExceptions, defaultFalse, defaultFalse, defaultFatalExceptionsList, getClassifier
Methods inherited from class org.springframework.kafka.listener.KafkaExceptionLogLevelAware
getLogLevel
-
Constructor Details
-
FailedBatchProcessor
public FailedBatchProcessor(@Nullable BiConsumer<org.apache.kafka.clients.consumer.ConsumerRecord<?, ?>, 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 BiConsumer<org.apache.kafka.clients.consumer.ConsumerRecord<?, ?>, 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
- theBackOffHandler
fallbackHandler
- the fall back handler.- Since:
- 2.9
-
-
Method Details
-
setRetryListeners
Description copied from class:FailedRecordProcessor
Set one or moreRetryListener
to receive notifications of retries and recovery.- Overrides:
setRetryListeners
in classFailedRecordProcessor
- Parameters:
listeners
- the listeners.
-
setLogLevel
Description copied from class:KafkaExceptionLogLevelAware
Set the level at which the exception thrown by this handler is logged.- Overrides:
setLogLevel
in classKafkaExceptionLogLevelAware
- Parameters:
logLevel
- the level (default ERROR).
-
setReclassifyOnExceptionChange
public void setReclassifyOnExceptionChange(boolean reclassifyOnExceptionChange) Set to false to not reclassify the exception if different from the previous failure. If the changed exception is classified as retryable, the existing back off sequence is used; a new sequence is not started. Default true. Only applies when the fallback batch error handler (for exceptions other thanBatchListenerFailedException
) is the default.- Parameters:
reclassifyOnExceptionChange
- false to not reclassify.- Since:
- 2.9.7
-
notRetryable
Description copied from class:ExceptionClassifier
Subclasses can override this to receive notification of configuration of not retryable exceptions.- Overrides:
notRetryable
in classExceptionClassifier
- Parameters:
notRetryable
- the not retryable exceptions.
-
setClassifications
public void setClassifications(Map<Class<? extends Throwable>, Boolean> classifications, boolean defaultValue) Description copied from class:ExceptionClassifier
Set 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:DeserializationException
MessageConversionException
ConversionException
MethodArgumentResolutionException
NoSuchMethodException
ClassCastException
- Overrides:
setClassifications
in classExceptionClassifier
- Parameters:
classifications
- the classifications.defaultValue
- whether or not to retry non-matching exceptions.- See Also:
-
BinaryExceptionClassifier(Map, boolean)
ExceptionClassifier.addNotRetryableExceptions(Class...)
-
removeClassification
Description copied from class:ExceptionClassifier
Remove an exception type from the configured list. By default, the following exceptions will not be retried:DeserializationException
MessageConversionException
ConversionException
MethodArgumentResolutionException
NoSuchMethodException
ClassCastException
ExceptionClassifier.defaultFalse()
has been called.- Overrides:
removeClassification
in classExceptionClassifier
- Parameters:
exceptionType
- the exception type.- Returns:
- the classification of the exception if removal was successful; null otherwise.
- See Also:
-
getFallbackBatchHandler
Return the fallback batch error handler.- Returns:
- the handler.
- Since:
- 2.8.8
-
doHandle
protected void doHandle(Exception thrownException, org.apache.kafka.clients.consumer.ConsumerRecords<?, ?> data, org.apache.kafka.clients.consumer.Consumer<?, ?> consumer, MessageListenerContainer container, Runnable invokeListener) -
handle
protected <K,V> org.apache.kafka.clients.consumer.ConsumerRecords<K,V> handle(Exception thrownException, org.apache.kafka.clients.consumer.ConsumerRecords<?, ?> data, org.apache.kafka.clients.consumer.Consumer<?, ?> consumer, MessageListenerContainer container, Runnable invokeListener)
-