Reputation: 674
I created a splitter for an exchange which decompresses the file and splits it on the basis of no of lines (Using Unix command 'split' for it). Returning list of messages containing these parts as messages.
Then set some properties on these as they need to be processed independently. Further the parent exchange needs to be processed after these parts are done. Now, I need a few properties set on the child to be set on the parent too. But the only way I could think of it was re-writing the setProperty part. Is there any way this could be achieved without redundancy.
I did try it another way, i.e., setting properties on the parent and trying to access them on the children isn't working too.
for (String feed: pc.parseUri("{{feedSources}}").split(",")) {
from("{{"+feed +".source}}").routeId(feed)
.setProperty("workDirectory", simple("{{workDirectory}}"))
.setProperty("feedName", simple(feed))
.setProperty("tableName", simple("{{"+feed+".tableName}}"))
.setProperty("options", simple("{{"+feed+".options}}"))
.split(beanExpression(new FileSplitter(), "split"))
.setProperty("dateFormat", simple("{{" + feed + ".dateFormat}}"))
.setProperty("headerFormat", simple("{{" + feed + ".headerFormat}}"))
.process(FileKeyProcessorFactory.getProcessor(feed))
.to("{{"+feed+".destination}}")
.end()
.process(new RSProcessor());
There are a few more properties to be set. Rewriting the code doesn't seems nice. What else could be the option.
Upvotes: 4
Views: 4458
Reputation: 56082
Use an AggregationStrategy
on the Splitter to merge in changes from each splitted message into the outgoing message of the parent splitter.
You can read more about this at Camel Split EIP documentation and at other EIPs which support the AggregationStrategy
as well.
Upvotes: 5
Reputation: 121
For example:
<beans xmlns="http://www.springframework.org/schema/beans">
<bean id="groupExchangeAggregationStrategy"
class="org.apache.camel.processor.aggregate.GroupedExchangeAggregationStrategy"
/>
</beans>
<split strategyRef="groupExchangeAggregationStrategy">
<xpath>//</xpath>
</split>
Upvotes: 0