首页 文章

读取器故障的Spring批量重试机制

提问于
浏览
1

我有一个 Spring 季批处理作业,每天运行一次 . 我实现了阅读器,处理器和编写器 . 假设在运行reader任务时发生任何异常,则整个作业将失败 . 我希望在5分钟后立即重新运行失败工作 . 请告诉我如何在 Spring 季批量实施或向我提供任何有信息的示例代码或网站 .

1 回答

  • 2

    看看Spring Retry . 它最初是作为Spring Batch的一部分开始的,但是从版本2.2.0开始,它已经转向独立项目(和依赖项) .

    能够以声明方式使用它特别好:

    import org.springframework.retry.annotation.Backoff;
    import org.springframework.retry.annotation.Retryable;
    
    public interface MyExampleService {
    
    @Retryable(maxAttempts = 3, backoff = @Backoff(delay = 2000))
    String callService() throws Exception;
    }
    

相关问题