【发布时间】:2021-12-13 17:53:29
【问题描述】:
实际SeekToCurrentErrorHandler有能力添加不可重试异常,意思是所有异常都是可重试的,除了最初的异常,并添加了X、Y、Z异常。
愚蠢的问题:有没有一种简单的方法可以做相反的事情:所有异常都不可重试,除了 X'、Y'、Z'...
【问题讨论】:
标签: spring apache-kafka spring-kafka
实际SeekToCurrentErrorHandler有能力添加不可重试异常,意思是所有异常都是可重试的,除了最初的异常,并添加了X、Y、Z异常。
愚蠢的问题:有没有一种简单的方法可以做相反的事情:所有异常都不可重试,除了 X'、Y'、Z'...
【问题讨论】:
标签: spring apache-kafka spring-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。
【讨论】:
setClassifications 而不是 addNotRetryableException 对吗?
false 的唯一方法。