I am developing Spring Boot Batch example. In this example, reading data from the CSV and based on status code values (like SUCCESS, REJECT, PENDING, COMPLETED) I want to write it into 4 different places (MySQL, XML, Postgres, Salesforce DB) while writing ?. I can see we can pass only 1 type of List of Customers to CompositeItemWriter method. How can I pass 4 different Customer List to CompositeItemWriter ?
Here I could think of using CompositeItemProcessor and CompositeItemWriter. In the CompositeItemProcessor I will take the decision of separating the records in all these processors and now question is how can I passed the SUCCESS to MYSQL, REJECT to XML, PENDING to Postgres and COMPLETED to Salesforce DB?
@Bean
public CompositeItemProcessor<Customer, Customer> compositeItemProcessor() throws Exception{
List<ItemProcessor<Customer, Customer>> delegates = new ArrayList<>();
delegates.add(new FilteringSuccessProcessor());
delegates.add(new FilteringRejectProcessor());
delegates.add(new FilteringPendingProcessor());
delegates.add(new FilteringCompletedProcessor());
CompositeItemProcessor<Customer, Customer> processor = new CompositeItemProcessor<>();
processor.setDelegates(delegates);
processor.afterPropertiesSet();
return processor;
}
FilteringSuccessProcessor.java
Like this I've created processor all the Status Codes and
public class FilteringSuccessProcessor implements ItemProcessor<Customer, Customer> {
@Override
public Customer process(Customer item) throws Exception {
if(item.getStatus == "SUCCESS"){
return item;
}
else
return null;
}
}
Now my question is - How can we pass 4 different data results to CompositeItemWriter to write it into 4 different places?
I though of using CustomerClassifier as well, but how to pass four different list to same writer ?
Any guidance ? This is very interesting use case, but look like critical to implement.