1
votes

Have a requirement to read files in spring batch, process it and persist it as one feed. One feed contains 50% of the information. When i have to persist the final result from the feeds, i need combine them using a common field and persist it as if like one item. Please see example below.

Feed1 fields: A|B|C|D|E
Feed2 fields: A|I|J|K|L

Final information that i need to persist is like:

A|B|C|D|E|I|J|K|L

Please suggest how i can achieve this in my spring batch job.

Thanks.

2
Are your input files sorted on the field 'A'? - Jimmy Praet
Jimmy, files are not sorted by field A. - user3222372

2 Answers

2
votes

If your input files would have been sorted you could have created a custom ItemReader implementation that performs a merge-sort on the files.

If sorting the input files is not an option, I think you'll need to store one of the input files temporarily into a data store. Then you can read from the second input file and enrich the records with the fields retrieved from the data store in your processor.

-1
votes

(Very) late answer, but you could use a plugin like this to handle the sorting and subsequent merging operations: https://github.com/upcrob/spring-batch-sort-merge