Camel pattern for multiple sources specific messages aggregation and redirect to destination
Asked Answered
N

2

6

I have one problem, and don't know how to solve it using camel. I searched for related EIP in camel documentation, but without results.

Now I have simple route:

<route id="routeId">
    <from uri="Source1"/>
    <from uri="Source2"/>
    <to   uri="Destination"/>
</route>

Both sources sends JMS messages to Destination and at some point when Source finish its job it send specific end message, with some flag. What I need to do is to collect or count those end messages and send single end message to destination when I receive end messages from both sources. Only when i receive two end messages (imagine that its just simple message with some header flag) then i should send single one to destination.

Sorry if problem explanation isn't clear enough.

Thanks in advance.

Neaten answered 14/8, 2014 at 13:33 Comment(0)
A
8

the Camel aggregator and filter patterns can be used for this scenario...

  • use a filter to detect "end" messages and route them through an aggregator
  • use a custom aggregation strategy to build up the single end message with a count
  • use a custom completion predicate to trigger the completion message

something like this...

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");
Astounding answered 14/8, 2014 at 15:17 Comment(0)
H
5

If you just want to pick from multiple inputs and does not want to perform any modification on the incoming message, you can do something like this:

from("URI1", "URI2", "URI3").to("DestinationUri");

for more info check this link it helped me

Hybris answered 31/1, 2019 at 13:17 Comment(1)
I cannot find a from() method which takes multiple URIs. Do you know which version of Camel did this work for you ? javadoc.io/doc/org.apache.camel/camel-core-engine/latest/org/…Drill

© 2022 - 2024 — McMap. All rights reserved.