Class ErrorHandlingUtils
java.lang.Object
org.springframework.kafka.listener.ErrorHandlingUtils
Utilities for error handling.
- Since:
- 2.8
-
Method Summary
Modifier and TypeMethodDescriptionstatic <K,
V> boolean checkDeserializer
(ConsumerFactory<K, V> consumerFactory, Properties consumerOverrides, boolean isValue, ClassLoader classLoader) Determine whether the key or value deserializer is an instance ofErrorHandlingDeserializer
.static Exception
findRootCause
(Exception exception) Find the root cause, ignoring anyListenerExecutionFailedException
andTimestampedException
.static String
recordsToString
(org.apache.kafka.clients.consumer.ConsumerRecords<?, ?> records) Represent the records as a comma-delimited String oftopic-part@offset
.static void
retryBatch
(Exception thrownException, org.apache.kafka.clients.consumer.ConsumerRecords<?, ?> records, org.apache.kafka.clients.consumer.Consumer<?, ?> consumer, MessageListenerContainer container, Runnable invokeListener, org.springframework.util.backoff.BackOff backOff, CommonErrorHandler seeker, BiConsumer<org.apache.kafka.clients.consumer.ConsumerRecords<?, ?>, Exception> recoverer, org.springframework.core.log.LogAccessor logger, KafkaException.Level logLevel, List<RetryListener> retryListeners, org.springframework.classify.BinaryExceptionClassifier classifier) Deprecated.static void
retryBatch
(Exception thrownException, org.apache.kafka.clients.consumer.ConsumerRecords<?, ?> records, org.apache.kafka.clients.consumer.Consumer<?, ?> consumer, MessageListenerContainer container, Runnable invokeListener, org.springframework.util.backoff.BackOff backOff, CommonErrorHandler seeker, BiConsumer<org.apache.kafka.clients.consumer.ConsumerRecords<?, ?>, Exception> recoverer, org.springframework.core.log.LogAccessor logger, KafkaException.Level logLevel, List<RetryListener> retryListeners, org.springframework.classify.BinaryExceptionClassifier classifier, boolean reClassifyOnExceptionChange) Retry a complete batch by pausing the consumer and then, in a loop, poll the consumer, wait for the next back off, then call the listener.static Exception
unwrapIfNeeded
(Exception exception) Remove aTimestampedException
, if present.
-
Method Details
-
retryBatch
@Deprecated public static void retryBatch(Exception thrownException, org.apache.kafka.clients.consumer.ConsumerRecords<?, ?> records, org.apache.kafka.clients.consumer.Consumer<?, ?> consumer, MessageListenerContainer container, Runnable invokeListener, org.springframework.util.backoff.BackOff backOff, CommonErrorHandler seeker, BiConsumer<org.apache.kafka.clients.consumer.ConsumerRecords<?, ?>, Exception> recoverer, org.springframework.core.log.LogAccessor logger, KafkaException.Level logLevel, List<RetryListener> retryListeners, org.springframework.classify.BinaryExceptionClassifier classifier) Retry a complete batch by pausing the consumer and then, in a loop, poll the consumer, wait for the next back off, then call the listener. When retries are exhausted, call the recoverer with theConsumerRecords
.- Parameters:
thrownException
- the exception.records
- the records.consumer
- the consumer.container
- the container.invokeListener
- theRunnable
to run (call the listener).backOff
- the backOff.seeker
- the common error handler that re-seeks the entire batch.recoverer
- the recoverer.logger
- the logger.logLevel
- the log level.retryListeners
- the retry listeners.classifier
- the exception classifier.- Since:
- 2.8.11
-
retryBatch
public static void retryBatch(Exception thrownException, org.apache.kafka.clients.consumer.ConsumerRecords<?, ?> records, org.apache.kafka.clients.consumer.Consumer<?, ?> consumer, MessageListenerContainer container, Runnable invokeListener, org.springframework.util.backoff.BackOff backOff, CommonErrorHandler seeker, BiConsumer<org.apache.kafka.clients.consumer.ConsumerRecords<?, ?>, Exception> recoverer, org.springframework.core.log.LogAccessor logger, KafkaException.Level logLevel, List<RetryListener> retryListeners, org.springframework.classify.BinaryExceptionClassifier classifier, boolean reClassifyOnExceptionChange) Retry a complete batch by pausing the consumer and then, in a loop, poll the consumer, wait for the next back off, then call the listener. When retries are exhausted, call the recoverer with theConsumerRecords
.- Parameters:
thrownException
- the exception.records
- the records.consumer
- the consumer.container
- the container.invokeListener
- theRunnable
to run (call the listener).backOff
- the backOff.seeker
- the common error handler that re-seeks the entire batch.recoverer
- the recoverer.logger
- the logger.logLevel
- the log level.retryListeners
- the retry listeners.classifier
- the exception classifier.reClassifyOnExceptionChange
- true to reset the state if a different exception is thrown during retry.- Since:
- 2.9.7
-
recordsToString
public static String recordsToString(org.apache.kafka.clients.consumer.ConsumerRecords<?, ?> records) Represent the records as a comma-delimited String oftopic-part@offset
.- Parameters:
records
- the records.- Returns:
- the String.
-
unwrapIfNeeded
Remove aTimestampedException
, if present. Remove aListenerExecutionFailedException
, if present.- Parameters:
exception
- the exception.- Returns:
- the unwrapped cause or cause of cause.
- Since:
- 2.8.11
-
findRootCause
Find the root cause, ignoring anyListenerExecutionFailedException
andTimestampedException
.- Parameters:
exception
- the exception to examine.- Returns:
- the root cause.
- Since:
- 3.0.7
-
checkDeserializer
public static <K,V> boolean checkDeserializer(ConsumerFactory<K, V> consumerFactory, Properties consumerOverrides, boolean isValue, ClassLoader classLoader) Determine whether the key or value deserializer is an instance ofErrorHandlingDeserializer
.- Type Parameters:
K
- the key type.V
- the value type.- Parameters:
consumerFactory
- the consumer factory.consumerOverrides
- consumer factory property overrides.isValue
- true to find the value deserializer.classLoader
- the class loader to load the deserializer class.- Returns:
- true if the deserializer is an instance of
ErrorHandlingDeserializer
. - Since:
- 3.0.10
-
retryBatch(Exception, ConsumerRecords, Consumer, MessageListenerContainer, Runnable, BackOff, CommonErrorHandler, BiConsumer, LogAccessor, org.springframework.kafka.KafkaException.Level, List, BinaryExceptionClassifier, boolean)
.