1
votes

I'm fairly new to Apache Camel and have a couple questions. I want my route to do the following:

  • load a list of lists in LoadSomeThingsProcessor
  • split twice so I can handle each item in the inner list
  • filter out some things I don't need
  • join all remaining exchanges from the inner split
  • then eventually join again (back to one exchange)

My route that looks something like the following:

from("direct:myRoute")
    .process(new LoadSomeThingsProcessor())
    .split(body())
    .streaming()
    .process(new SomeProcessor())
    .split(body())
    .streaming()
    .filter(new SomeFilter())
    .aggregate(header("myHeader", new MyAggregationStrategy())
    .completionPredicate(new MyCompletionPredicate())
    // more processors
    // aggregate again (should just be one exchange after this point
    // more processors
    .to("direct:someOtherRoute");

MyCompletionPredicate's matches method is just:

return exchange.getIn().getProperty("CamelSplitComplete", Boolean.class);

I want to ensure that ALL exchanges in each split are aggregated together before I continue.

My questions are: - The CamelSplitComplete header is somehow never true. What could cause this? - Is trying to aggregate inside a nested split going to cause any issues? - What happens if the last exchange (the one that is supposed to have CamelSplitComplete = true is filtered out? How can I know that I have aggregated all my exchanges together? - Is this even the right way to approach this problem? If no, what else should I consider?

FYI my aggregation strategy just takes the bodies of the new exchange and adds them to the body of the old exchange.

Many thanks in advance.

1

1 Answers

-3
votes

See the Composed Message Processor EIP: https://camel.apache.org/components/latest/eips/composed-message-processor.html

And there is an example with the title Splitter Only which allows to do a fork/join style. You can still use a filter in the splitter only to filter out specific items etc.

And try to not make it to complicated with 2 x splits and all kind of stuff - keep it a bit simpler then its much easier to use, test and work with.