Question

I have a situation where I want to pass data into an Aggregator, but I don't want the aggregator to do anything until it has received messages from 3 distinct routes:

<route id="route-1">
    <from uri="direct:fizz" />

    <to uri="bean:bean1?method=process" />

    <setHeader headerName="id">
        <constant>1</constant>
    </setHeader>

    <to uri="direct:aggregator" />
</route>

<route id="route-2">
    <from uri="direct:buzz" />

    <to uri="bean:bean2?method=process" />

    <setHeader headerName="id">
        <constant>2</constant>
    </setHeader>

    <to uri="direct:aggregator" />
</route>

<route id="route-3">
    <from uri="direct:foo" />

    <to uri="bean:bean3?method=process" />

    <setHeader headerName="id">
        <constant>3</constant>
    </setHeader>

    <to uri="direct:aggregator" />
</route>

<route id="aggregator-route">
    <from uri="direct:aggregator" />

    <aggregate strategyRef="myAggregationStrategy" completionSize="1">
        <correlationExpression>
            <simple>header.id</simple>
        </correlationExpression>
        <to uri="bean:lastBean?method=process" />
    </aggregate>
</route>

The way this is configured, when the aggregator's completionSize is set to 1 or 2, the aggregated Exchange is routed on to my lastBean. However, if I set completionSize to 3, for some reason, lastBean#process never gets invoked.

I'm sure that I'm using header.id and the aggregator incorrectly here. In the correlationExpression, I just need to make sure that we have 1 Message from each of the 3 routes.

So my question: what do I need to do to make my aggregator "wait" until it has received 1 message from route-1, 1 message from route-2 and 1 message from route-3?

Was it helpful?

Solution

If you are correlating messages from three routes, there needs to be a way for them all to have a matching header.id value by the time they reach the aggregating route.

In your example, each route sets a different id value so there would be no match. If you set the id value to "1" in each route, I think it would start to work as expected.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top