AdjustingForInflation
AdjustingForInflation

Reputation: 1611

Camel Multicast not working

Camel 2.11.0 here. I have the following Camel routes:

<route id="main-route"> 
    <from uri="timer://runOnce?repeatCount=1&amp;delay=10" /> 

    <to uri="bean:loggingBean?method=main" />

    <to uri="bean:processorBean?method=doSomething" />

    <to uri="bean:loggingBean?method=afterProcessing" />

    <multicast> 
        <to uri="direct:validator" />
        <to uri="direct:rejector" /> 
    </multicast> 
</route>

<route id="validator-route"> 
    <from uri="direct:validator" />
    <to uri="bean:loggingBean?method=validator" />
</route>

<route id="rejector-route"> 
    <from uri="direct:rejector" /> 
    <to uri="bean:loggingBean?method=rejector" />
</route>

...where the loggingBean looks like:

public class LoggingBean {
    public void main(Exchange e) {
        System.out.println("Starting main route...");
    }

    public void afterProcessing(Exchange e) {
        System.out.println("Processing input...");
    }

    public void validator(Exchange e) {
        System.out.println("In validator route...");
    }

    public void rejector(Exchange e) {
        System.out.println("In rejector route...");
    }
}

When I run this code, I get the following console output:

Starting main route...
Processing input...
In validator route...

Because we're multi-casting here, I would have expected it to also include the rejector's output and look like:

Starting main route...
Processing input...
In validator route...
In rejector route...

So it seems that the Multicaster is only sending to the first element nested inside it (in the Spring XML) and not the second. Hmmm, interesting. So then I changed the <multicast> element to look like the following:

<multicast> 
    <to uri="direct:rejector" /> 
    <to uri="direct:validator" />
</multicast> 

This time, the console output is as follows:

Starting main route...
Processing input...
In rejector route...

So this is confirmed: the <multicast> is only broadcasting the exchange to the first child element listed underneath it. Why, and how can I fix this?

Upvotes: 0

Views: 1563

Answers (2)

Peter Keller
Peter Keller

Reputation: 7636

I tested your routes and everything worked as expected:

<multicast>
    <to uri="direct:rejector" />
    <to uri="direct:validator" />
</multicast>

This logs

Starting main route...
Processing input...
In rejector route...
In validator route...

And with

<multicast>
    <to uri="direct:validator" />
    <to uri="direct:rejector" />
</multicast>

This logs

Starting main route...
Processing input...
In validator route...
In rejector route...

Perhaps, you read the wrong Camel configuration?

Upvotes: 1

Related Questions