我在Web服务器上运行了两种不同的服务.这两个服务都有一个名为'xyz'的操作,具有以下参数.
服务1:
Public String xyx(Student object) {}
服务2:
public String xyz(Employee object){}
现在我有一个客户端将根据它收到的消息调用其中一个服务的操作.该消息将作为骆驼交换机收到.所以我需要确定消息的类型,然后调用适当的服务.
如何识别作为camel exchange接收的消息的原始类型.
谢谢.
或者你可以这样做:
from("foo:incommingroute")
.choice()
.when(simple("${body} is 'java.lang.String'"))
.to("webservice:Student")
.when(simple("${body} is 'foo.bar.Employee'"))
.to("webservice:Employee")
.otherwise()
.to("jms:Deadletter")
.end();
Run Code Online (Sandbox Code Playgroud)
我会在标题中设置一个值来指示它是哪个服务,然后在驼峰路由上发送它.这种方法只是一种方法.Christian Schneider还有另一个出色的解决方案,我现在可能会使用更多的解决方案,因为我之前对Camel有了更多的了解.然而,两者都会达到同样的效果,取决于你问谁,一个人可能比另一个人更清楚.
例如,您可以这样做:
public void foo(Exchange exchange){
exchange.getIn().setHeader("MsgType", "Student");
}
Run Code Online (Sandbox Code Playgroud)
然后,您可以在Java DSL甚至Spring 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();
Run Code Online (Sandbox Code Playgroud)
在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>
Run Code Online (Sandbox Code Playgroud)
您还可以在此链接http://camel.apache.org/content-enricher.html上查看更丰富的模式.基本上我所建议的是遵循更丰富的模式.如果你能告诉我你如何向Camel发送消息,那么我可能会提供更多帮助.
希望这能给你一些想法,如果代码中有语法错误等,抱歉我在公共汽车站,没时间检查它.
| 归档时间: |
|
| 查看次数: |
7142 次 |
| 最近记录: |