骆驼组播无法正常工作

时间:2014-01-30 15:49:38

标签: java apache-camel routes multicast

Camel 2.11.0在这里。我有以下Camel路线:

<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>

... loggingBean的样子:

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...");
    }
}

当我运行此代码时,我得到以下控制台输出:

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

因为我们在这里广播,所以我希望它也包含拒绝者的输出,如下所示:

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

所以似乎Multicaster只发送到嵌套在其中的第一个元素(在Spring XML中),而不是第二个。嗯,有趣。然后我将<multicast>元素更改为如下所示:

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

这次,控制台输出如下:

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

所以这一点得到了证实:<multicast>只是将交换广播到它下面列出的第一个子元素。 为什么,以及如何解决此问题?

2 个答案:

答案 0 :(得分:1)

答案 1 :(得分:1)

我测试了你的路线,一切都按预期工作:

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

记录

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

并且

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

记录

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

也许,你读错了Camel配置?