Processing two files in a spring batch

邮差的信 提交于 2019-12-08 06:35:58

问题


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.


回答1:


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.




回答2:


(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



来源:https://stackoverflow.com/questions/28005816/processing-two-files-in-a-spring-batch

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!