Design a Spring batch application to read data from different resources(Flat files)

Viewed 131

I am developing a batch application using (Spring boot, java, and Spring batch) for which I need to read data from different locations. Below is my use case:

  • Multiple paths such as C://Temp//M1, C://Temp//M2 , both locations can contain identical files with same data such as C://Temp//M1//File1.txt, C://Temp//M2//File1.txt, and C://Temp//M1//File2.txt, C://Temp//M2//File2.txt
  • At first, I need to merge them in memory if an identical file exists at both locations before starting batch after removing duplicates and pass the merged in-memory data as an argument to the reader.

I have designed batch using multiresourceitemreader which reads flat files and processes them but not able to achieve in-memory merging and duplicate removal from multiple files. So may you please have a look and suggest me a way how can I achieve this?

2 Answers

If you are aware of Kafka try Kafka connect framework. Use the Confluent platform to easily use their connectors.

Then consume from Kafka into your Spring application.

https://www.confluent.io/hub

If you are interested in Kafka I'll explain to you in detail

Through my experience I have found the usage of BeanIO library priceless when it comes to dealing with flat files. Also it integrates with spring batch. http://beanio.org/

Which regards of reading from 2 locations you can:

  1. Implement your reader as a composite that read first line from file 1 then from file two
  2. you first read through the reader file 1 and inside the prosessor you enrich with data from file number 2.
  3. premerge the files
Related