Note that there are some explanatory texts on larger screens.

plurals
  1. POApache Camel: multicast with aggregation - AggregationStrategy called too often
    primarykey
    data
    text
    <p>I have the following strange (or at least unclear to me) behaviour for a multi-cast + aggregation. Consider the following route:</p> <pre><code> from("direct:multicaster") .multicast() .to("direct:A", "direct:B") .aggregationStrategy(new AggregationStrategy() { @Override public Exchange aggregate(Exchange oldExchange, Exchange newExchange) { if (oldExchange == null) { List firstResult = newExchange.getIn().getBody(List.class); newExchange.getIn().setBody(ImmutableList.copyOf(firstResult)); return newExchange; } else { List oldResults = oldExchange.getIn().getBody(List.class); List newResults = newExchange.getIn().getBody(List.class); ImmutableList aggResult = ImmutableList.copyOf(Iterables.concat(oldResults, newResults)); oldExchange.getIn().setBody(aggResult); return oldExchange; } } }) .end() // .to("log:bla") </code></pre> <p>Essentially, this route takes an input, sends it to <code>direct:A</code> and <code>direct:B</code>, expects lists from these two endpoints and concatenates them (the comment in the last line is there for a reason I will explain later).</p> <p>Now assume that these two endpoints "return" the lists [A] and [B], respectively. If I send the message <code>M</code> to <code>direct:multicaster</code>, then the aggregator is called once with <code>oldExchange = null</code> and <code>newExchange.in.body=[A]</code>, then with <code>oldExchange.in.body=[A]</code> and <code>newExchange.out.body=[B]</code> (as it is supposed to do).</p> <p>All good up to this point. But the aggregator is called once more with <code>oldExchange.in.body=[A,B]</code> and <code>newExchange.in=M</code> (<code>M</code> is the initial message). This looks similar to an included enrichment pattern.</p> <p>You can get the expected behaviour by removing the comment in the last line, i.e. simply adding a dummy <code>to("log:bla")</code>. With this everthing behaves as expected.</p> <h3>Update: Trying (cf. the hint provided by Claus)</h3> <pre><code> .multicast() .aggregationStrategy(aggStrategy) .to("direct:A", "direct:B") .end() </code></pre> <p>and</p> <pre><code> .multicast(aggStrategy) .to("direct:A", "direct:B") .end() </code></pre> <p>both result in the same behaviour.</p> <p>What is happening here - what did I get wrong?</p> <p>thanks in advance markus </p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload