首页 > 解决方案 > 带有 RetryableException 处理(而不是 NotRetryableException)的 SeekToCurrentErrorHandler

问题描述

实际SeekToCurrentErrorHandler可以添加不可重试的异常,即除了最初的异常外,所有的异常都是可重试的,并添加了 X、Y、Z 异常。

愚蠢的问题:有没有一种简单的方法可以做相反的事情:所有异常都不可重试,除了 X',Y',Z'...

标签: springapache-kafkaspring-kafka

解决方案


是的,可以看到该类的这个配置方法:

/**
 * 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:
 * <ul>
 * <li>{@link DeserializationException}</li>
 * <li>{@link MessageConversionException}</li>
 * <li>{@link MethodArgumentResolutionException}</li>
 * <li>{@link NoSuchMethodException}</li>
 * <li>{@link ClassCastException}</li>
 * </ul>
 * All others will be retried.
 * When calling this method, the defaults will not be applied.
 * @param classifications the classifications.
 * @param defaultValue whether or not to retry non-matching exceptions.
 * @see BinaryExceptionClassifier#BinaryExceptionClassifier(Map, boolean)
 * @see #addNotRetryableExceptions(Class...)
 */
public void setClassifications(Map<Class<? extends Throwable>, Boolean> classifications, boolean defaultValue) {

因此,要使所有内容都不可重试,您需要提供一个默认值作为false. 然后,该地图应包含您希望可重试的那些异常,键的值为true.


推荐阅读