SpringBatch from entry to abandon retry robust configuration of 005

Sometimes because of short-term failure, resulting in Batch execution failure, such as network jitter, etc., in order to Batch robustness, this time on the need to retry several times to exclude Batch status as temporary factors caused the failure.

It should be noted that from later versions 2.2.0 Spring Batch, Retry have been independently into a single Jar.

Batch retry settings:

the retry ()
source as follows:

public FaultTolerantStepBuilder<I, O> retry(Class<? extends Throwable> type) {
        retryableExceptionClasses.put(type, true);
        return this;
    }

The definition needs to be retried captured exception, can be called multiple times, each call will be an exception to the list inside.

NORETRY ()
source as follows:

    public FaultTolerantStepBuilder<I, O> noRetry(Class<? extends Throwable> type) {
        retryableExceptionClasses.put(type, false);
        return this;
    }

Each call will need to exclude parameters added to the list of exceptions inside.

retryLimit ()
source as follows:

    public FaultTolerantStepBuilder<I, O> retryLimit(int retryLimit) {
        this.retryLimit = retryLimit;
        return this;
    }

The maximum number of retries. Failure will directly speak about this number.

retryContextCache ()
source as follows:

    public FaultTolerantStepBuilder<I, O> retryContextCache(RetryContextCache retryContextCache) {
        this.retryContextCache = retryContextCache;
        return this;
    }

RetryContext used to store the cache.

retryPolicy ()
source as follows:

    public FaultTolerantStepBuilder<I, O> retryPolicy(RetryPolicy retryPolicy) {
        this.retryPolicy = retryPolicy;
        return this;
    }

Some simple retry, retry can be achieved by a retry (), noRetry () and retryLimit () configuration. Spring Batch also supports retries to implement complex logic by setting RetryPolicy. RetryPolicy (retry strategy) interface is defined as follows:

canRetry () How to determine whether to retry, open () executed when the retry start, close () is executed at the end of retries, each retry called once registerThrowable () to initialize the context.

The system provides several default implementation class:

Specific implementation class action, see the following table:

Implementation class effect
NeverRetryPolicy RetryCallback only allowed to call once, retry is not permitted
AlwaysRetryPolicy Allow unlimited retries until it succeeds, this way logic incorrectly can cause an infinite loop
SimpleRetryPolicy 固定次数重试策略,默认重试最大次数为3次,RetryTemplate默认使用的策略
TimeoutRetryPolicy 超时时间重试策略,默认超时时间为1秒,在指定的超时时间内允许重试
CircuitBreakerRetryPolicy 有熔断功能的重试策略,需设置3个参数openTimeout、resetTimeout和delegate,
CompositeRetryPolicy 组合重试策略,有两种组合方式,乐观组合重试策略是指只要有一个策略允许重试即可以,悲观组合重试策略是指只要有一个策略不允许重试即可以,但不管哪种组合方式,组合中的每一个策略都会执行
ExceptionClassifierRetryPolicy 为不同的异常指定不同的重试策略

Guess you like

Origin www.cnblogs.com/ckp-henu/p/springbatch-cong-ru-men-dao-fang-qi0052.html