In Spring batch I need to pass the items read by an ItemReader to two different processors and writer. What I'm trying to achieve is that...
+---> ItemProcessor#1 ---> ItemWriter#1
|
ItemReader ---> item ---+
|
+---> ItemProcessor#2 ---> ItemWriter#2
This is needed because items written by ItemWriter#1 should be processed in a completely different way compared to the ones written by ItemWriter#2. Moreover, ItemReader reads item from a database, and the queries it executes are so computational expensive that executing the same query twice should be discarded.
Any hint about how to achieve such set up ? Or, at least, a logically equivalent set up ?
This solution is valid if your item should be processed by processor #1 and processor #2
You have to create a processor #0 with this signature:
where
CompositeResultBeanis a bean defined asIn your Processor #0 just delegate work to processors #1 and #2 and put result in
CompositeResultBeanYour own writer is a
CompositeItemWriterthat delegate to writerCompositeResultBean.result1orCompositeResultBean.result2(look at PropertyExtractingDelegatingItemWriter, maybe can help)