In my Spring Integration powered project I have a splitter and payload-router for sending my data to various transformers. The new "transformed" objects are then passed back to an aggregator and processed.
Now I want to split up my aggregated results so they are persisted properly, since I need to route some of the objects to a seperate outbound-channel-adapter. To achieve this, I added a second splitter after my aggregator; but it seems only the first element in the aggregated collection is passed to the router.
This is my current flow:
<splitter ref="articleContentExtractor" />
<!-- This router works exactly as expected -->
<payload-type-router>
... routing to various transformers ...
... results are sent to articleOutAggregateChannel ...
</payload-type-router>
<aggregator ref="articleAggregator" />
<splitter />
<!-- This is where it seems to go wrong, the second
splitter returns only the first object in the collection -->
<payload-type-router resolution-required="true">
<mapping type="x.y.z.AbstractContent" channel="contentOutChannel" />
<mapping type="x.y.z.Staff" channel="staffOutChannel" />
</payload-type-router>
<outbound-channel-adapter id="contentSaveService" ref="contentExporter"
method="persist" channel="contentOutChannel" />
<outbound-channel-adapter id="staffSaveService" ref="staffExporter"
method="persist" channel="staffOutChannel" />
And my Aggregator code:
@Aggregator
public List<? super BaseObject> compileArticle(List<? super BaseObject> parts) {
// Search for the required objects for referencing
Iterator<? super BaseObject> it = parts.iterator();
Article article = null;
List<Staff> authors = new ArrayList<Staff>();
while (it.hasNext()) {
Object part = it.next();
if (part instanceof Article) {
article = (Article)part;
}
else if (part instanceof Staff) {
authors.add((Staff)part);
}
}
// Apply references
article.setAuthors(authors);
return parts;
}
What am I doing wrong? Am I using my aggregator properly?
Note: If I just remove both the aggregator and second splitter altogether, the rest of the flow works perfectly.