I am looking for loading people records from multiple files based on location. Is there any easy support by Spring batch to load multiple files named location weise? Easy Country_people.zip -> Location1 (folder1) containing 3 text files(people_education.txt, people_address.txt, people_income.txt)
-> Location2 (folder2) containing 3 text files(people_education.txt, people_address.txt, people_income.txt)
-> Location3 (folder3) containing 3 text files(people_education.txt, people_address.txt, people_income.txt)
You can try using Partitioner
to get the data from multiple files
https://docs.spring.io/spring-batch/docs/current/reference/html/scalability.html#partitioning
public class CustomMultiResourcePartitioner implements Partitioner {
@Override
public Map<String, ExecutionContext> partition(int gridSize) {
Map<String, ExecutionContext> map = new HashMap<>(gridSize);
int i = 0, k = 1;
for (Resource resource : resources) {
ExecutionContext context = new ExecutionContext();
Assert.state(resource.exists(), "Resource does not exist: "
+ resource);
context.putString(keyName, resource.getFilename());
context.putString("opFileName", "output"+k+++".xml");
map.put(PARTITION_KEY + i, context);
i++;
}
return map;
}
}