【问题标题】:SeekToCurrentErrorHandler with RetryableException handling (and not NotRetryableException)带有 RetryableException 处理(而不是 NotRetryableException)的 SeekToCurrentErrorHandler
【发布时间】:2021-12-13 17:53:29
【问题描述】:

实际SeekToCurrentErrorHandler有能力添加不可重试异常,意思是所有异常都是可重试的,除了最初的异常,并添加了X、Y、Z异常。

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

【问题讨论】:

    标签: spring apache-kafka spring-kafka


    【解决方案1】:

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

    /**
     * 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

    【讨论】:

    • 我明白了,我必须在 STCEH 中使用 setClassifications 而不是 addNotRetryableException 对吗?
    • 对。根据您的要求,您希望覆盖所有其他异常的默认值。这是将默认值更改为 false 的唯一方法。
    猜你喜欢
    • 1970-01-01
    • 2021-04-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-10-07
    • 1970-01-01
    • 2012-12-18
    • 2016-04-09
    相关资源
    最近更新 更多