繁体   English   中英

如何在Spring批处理中重试Tasklet?

[英]How to Retry tasklet in Spring batch?

如何重试方法调用程序任务,我知道如果块任务失败,则可以重试,并且可以设置退避策略,但是在方法调用程序任务xsd中,我找不到重试选项。 如果失败,是否还有其他选择可以重试该任务。

您可以使用spring-retry和声明性retry ; 只需应用<aop:config>标记并配置拦截器即可。

要更改策略或侦听器,只需要将RetryTemplate的实例注入到拦截器中

当我遇到REST调用失败以读取数据时,我需要重试。 在春季重试不会重试读取器故障。 该解决方案基本上是@Luca使用RetryTemplate和aop所说的。

<bean id="retryAdvice"
    class="org.springframework.retry.interceptor.RetryOperationsInterceptor">
    <property name="retryOperations">
        <bean class="org.springframework.retry.support.RetryTemplate">
            <property name="retryPolicy">
                <bean class="org.springframework.retry.policy.SimpleRetryPolicy">
                    <property name="maxAttempts" value="5" />
                </bean>
            </property>
            <property name="backOffPolicy">
                <bean class="org.springframework.retry.backoff.ExponentialBackOffPolicy">
                    <property name="initialInterval" value="3000"></property>
                    <property name="maxInterval" value="60000"></property>
                </bean>
            </property>
        </bean>
    </property>
</bean>
<aop:config>
    <aop:pointcut
        expression="execution(* com.mypackage.MyService.get*(..))"
        id="remoteMethodPointCut"></aop:pointcut>
    <aop:advisor pointcut-ref="remoteMethodPointCut"
        advice-ref="retryAdvice" />
</aop:config>

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM