我会在头文件中设置一个值来指示它是哪个服务,然后在骆驼路由上发送这个值。这种方法只是这样做的一种方式。 Christian Schneider有另一个很好的解决方案,我现在可能会使用更多的解决方案,因为我现在已经更多地使用了骆驼。但是,两者都会达到同样的效果,并且取决于你问的人可能比其他人更清楚。
例如,你可以这样做:
public void foo(Exchange exchange){
exchange.getIn().setHeader("MsgType", "Student");
}
然后,您可以在任何在Java DSL,甚至春季DSL头过滤。
在Java DSL,你会做这样的事情(伪代码)
from("foo:incommingroute")
.choice()
.when(header("MsgType").equals("Student"))
.to("webservice:Student")
.when(header("MsgType").equals("Employee"))
.to("webservice:Employee")
.otherwise()
.to("jms:Deadletter")
.end();
在Spring DSL,你会做这样的事情(伪代码)
<route>
<from uri="foo:incommingroute"/>
<choice>
<when>
<simple>${header.MsgType} equals 'Student'</simple>
<to uri="webservice:Student"/>
</when>
<when>
<simple>${header.MsgType} equals 'Employee'</simple>
<to uri="webservice:Employee"/>
</when>
<otherwise>
<to uri="jms:badOrders"/>
<stop/>
</otherwise>
</choice>
<to uri="jms:Deadletter"/>
</route>
您也可以看看在这个链接http://camel.apache.org/content-enricher.html丰富模式。基本上我建议遵循丰富的模式。如果你能告诉我你是怎么给骆驼发送消息的,那么我可能会帮助更多。
希望这给你一些想法,如果在代码中有语法错误等,抱歉,我在公交车站,没有时间检查它。 。
只是一个想法的,为什么不倾头的日志组件,它将打印他们到码头。也许头文件中有些东西可以帮助您确定如何区分它们。 – Namphibian 2012-04-11 05:44:10