I am trying to make a request to an inbound http endpoint that uses <recipient-list> and a Custom Aggregator to combine multiple results. How do I get my inbound http endpoint to “wait” for the result of the Custom Aggregator?
Here are my sample flows. The Aggregator works perfectly. But because is asynchronous, the inbound http endpoint returns immediately. What I’d really like to do is return the result from the Custom Aggregator as a response to the http endpoint. I feel like I am missing something simple.
<flow name="AggregationExample">
<http:inbound-endpoint
exchange-pattern="request-response"
host="localhost"
port="8082"
path="test/aggregate"
/>
<recipient-list evaluator="groovy" expression="['vm://source1','vm://source2']"></recipient-list>
<!-- How do I wait for result of custom aggregator? -->
</flow>
<flow name="SourceAggregation">
<vm:inbound-endpoint path="sourceresult" />
<custom-aggregator failOnTimeout="true" class="com.example.MySourceAggregator"/>
<logger message="RESULTS: #[payload]"/>
</flow>
<flow name="Source1">
<vm:inbound-endpoint path="source1" />
<set-payload value="#[groovy:Thread.currentThread().getContextClassLoader().getResourceAsStream('example-source1.json').text]"/>
<vm:outbound-endpoint path="sourceresult" />
</flow>
<flow name="Source2">
<vm:inbound-endpoint path="source2" />
<set-payload value="#[groovy:Thread.currentThread().getContextClassLoader().getResourceAsStream('example-source2.json').text]"/>
<vm:outbound-endpoint path="sourceresult" />
</flow>
Use a
request-replyrouter in theAggregationExampleflow instead of a recipient list: dispatch to another flow that does the dispatching toSource1andSource2.Generally speaking, I’m unsure about what you’re trying to achieve though: did you build this contraption just to read two files in parallel? Or is there more to it? If just for that, are you sure it’s really worth it: aren’t there any physical limitations to concurrent file reads? If it’s all for optimization, caching would potentially be a better path.
Also, if the recipients in
recipient-listare static, why using this router and not anallrouter?Finally, did you have issues with MEL that you’re using Groovy expressions to read the files instead?