Camel model for aggregating individual messages and redirecting recipients
I have one problem and I don't know how to solve it with camel. I searched for the relevant EIP in the camel documentation but no results.
I now have a simple route:
<route id="routeId">
<from uri="Source1"/>
<from uri="Source2"/>
<to uri="Destination"/>
</route>
Both sources send JMS messages to Destination and at some point when Source finishes its job it sends a specific destination message with some flag. What I need to do is collect or calculate these end messages and send a one-way message to the destination when I receive end messages from both sources. It is only when I receive two final messages (imagine it is a simple message with some header flag) that I have to send one message to the destination.
Sorry if the explanation for the problem is not clear enough.
Thanks in advance.
source to share
camel aggregator and filter model can be used for this scenario ...
- use a filter to detect "final" messages and route them through the aggregator
- use your own aggregation strategy to create a single end post count
- use a custom completion predicate to trigger the completion message
something like that...
from("source1").to("direct:aggregateRoute");
from("source2").to("direct:aggregateRoute");
from("direct:aggregateRoute")
.filter(header("isEndMessage").isEqualTo("true"))
.aggregate(constant(true), new MyAggregationStrategy())
.completionPredicate(new MyCompletionStrategy())
.to("destination");
source to share