Retry not working with FaultTolerantStepBuilder

后端 未结 1 1595
隐瞒了意图╮
隐瞒了意图╮ 2021-01-27 10:53

I am trying to build a retry into my error-prone itemreader. I have set up a small POC to test if everything is working, but I am not able to get retries running. Here is what I

相关标签:
1条回答
  • 2021-01-27 11:20

    "Am I doing something wrong or is this a bug?" seems like a bug. Oddly enough throwing the exception on write seems to be fine.

    @Bean
    public Job retrySample() {
        return jobBuilderFactory.get("retrySample").start(mockStep()).build();
    }
    
    @Bean
    public Step mockStep() {
    
        return stepBuilderFactory.get("mockStep")
                    .<String, String>chunk(1)
                    .reader(itemReader()) 
                    .writer(itemWriter())
                    .faultTolerant()
                    .retry(Exception.class)
                    .retryLimit(10)
    
                    .build();            
    
    }
    
    @Bean
    @JobScope
    public ItemReader<String> itemReader() {
        return new ItemReader<String>() {
    
            @Override
            public String read() throws Exception {
                return "dkafj";
            }
        };
    }
    
    @Bean
    @JobScope
    public ItemWriter<String> itemWriter() {
        return new ItemWriter<String>() {
            @Override
            public void write(List<? extends String> items) throws Exception {
                items.forEach(item -> {System.out.println("got" + item);});
                throw new Exception("booom");
    
            }
        };           
    }
    

    Logs:

     2016-12-08 16:04:09.618  INFO 9040 --- [           main] o.s.b.c.l.support.SimpleJobLauncher      : Job: [SimpleJob: [name=retrySample]] launched with the following parameters: [{runId=Job}]
    2016-12-08 16:04:09.651  INFO 9040 --- [           main] o.s.batch.core.job.SimpleStepHandler     : Executing step: [mockStep]
    gotdkafj
    gotdkafj
    gotdkafj
    gotdkafj
    gotdkafj
    gotdkafj
    gotdkafj
    gotdkafj
    gotdkafj
    gotdkafj
    2016-12-08 16:04:09.707 ERROR 9040 --- [           main] o.s.batch.core.step.AbstractStep         : Encountered an error executing step mockStep in job retrySample
    
    org.springframework.retry.ExhaustedRetryException: Retry exhausted after last attempt in recovery path, but exception is not skippable.; nested exception is java.lang.Exception: booom
        at org.springframework.batch.core.step.item.FaultTolerantChunkProcessor$5.recover(FaultTolerantChunkProcessor.java:403) ~[spring-batch-core-3.0.7.RELEASE.jar:3.0.7.RELEASE]
    

    Here is the link to the Spring Batch JIRA

    0 讨论(0)
提交回复
热议问题