vishal
vishal

Reputation: 4083

How to handle FlatFileItemReader exception when resource is not available to call other step and retry same step which threw exception?

I am using spring batch remote partitioning. My first step prepares input files for all other steps. Other steps process input files.

To create input files on all 4 servers, my fist step should run on all servers. So I have set up consumer concurrency 1 on all servers and grid size 4 = number of servers.

But consumers on some servers consumes step execution request messages multiple times so on other servers the first step do not run and therefore input files do not get prepared which leads to failure of other steps which tries to process those file.

I want to run the first step if any step throw exception if resource (input file) is not available and then retry the same step which threw the exception.

How do I handle the exception thrown by FlatFileItemReader in strict mode if resource is not available and call the first step to prepare input files and retry same step which threw exception ?

More details are here

In documentation there are two types of exceptions mentioned

For this reason, Spring Batch provides a hierarchy of exceptions for handling parse exceptions: FlatFileParseException and FlatFileFormatException. FlatFileParseException is thrown by the FlatFileItemReader when any errors are encountered while trying to read a file. FlatFileFormatException is thrown by implementations of the LineTokenizer interface, and indicates a more specific error encountered while tokenizing.

Does it mean FlatFileParseException is thrown when there is an error while reading existing file or it is thrown when file do not exist at all ?

or in source code,

FlatFileItemReader<T> extends AbstractItemCountingItemStreamItemReader where AbstractItemCountingItemStreamItemReader:read throws UnexpectedInputException ?

I am not sure how to use them ?

Upvotes: 0

Views: 2052

Answers (1)

Luca Basso Ricci
Luca Basso Ricci

Reputation: 18403

For this kind of problem use a JobExecutionDecider to redirect your job flow to step A if file doesn't exist of step B in other case.
This solution is more clear and show the real flow of your job without hide behind exception management (what about if SB mantainer decide to change FlatFileReader exception hierarchy, for example)?

Upvotes: 1

Related Questions