I have the following ItemReader
:
import org.springframework.batch.item.ExecutionContext;
import org.springframework.batch.item.ItemStreamException;
import org.springframework.batch.item.file.FlatFileItemReader;
import org.springframework.batch.item.file.LineMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.io.FileSystemResource;
import org.springframework.retry.annotation.Retryable;
import org.springframework.stereotype.Service;
@Service
public class MyReader extends FlatFileItemReader<Holding> {
@Autowired
public MyReader(LineMapper<Holding> lineMapper, File loadFile) {
setResource(new FileSystemResource(loadFile));
final int NUMBER_OF_HEADER_LINES = 1;
setLinesToSkip(NUMBER_OF_HEADER_LINES);
setLineMapper(lineMapper);
}
@Override
@Retryable(value=ItemStreamException.class, maxAttempts=5, backoff=@Backoff(delay=1800000))
public void open(ExecutionContext executionContext) throws ItemStreamException {
super.open(executionContext);
}
}
The file to be read (i.e. loadFile
) may or may not be available when running the job. If the file is not available, I want the reader to sleep ~30 minutes and then retry opening the file. If after five attempts, the file is not found it can fail as it normally would by throwing ItemStreamException
.
Unfortunately, the above code does not attempt to retry opening the file. It throws ItemStreamException
on the first call to open and does not retry open.
Can someone please explain how to do this? Note: I do have @EnableRetry
on the SpringBootApplication
class.