Apache的骆驼条件路由 [英] Apache Camel conditional routing

查看:300
本文介绍了Apache的骆驼条件路由的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有两个操作的服务。

I have a service which has two operations.

RegisterUser
UpdateUser

我般地击溃:

<camel:route id="myRoute">
    <camel:from uri="cxf:bean:myListenerEndpoint?dataFormat=POJO&amp;synchronous=true" />            
    <camel:bean ref="processor" method="processMessage"/>
    <camel:to uri="xslt:file:resources/service/2.0.0/UserRegistration.xsl"/>
    <camel:to uri="cxf:bean:myTargetEndpoint"/>
</camel:route>

在我的处理器豆,当我指定:

In my processor bean, when I specify:

RegisterUser registerUser = exchange.getIn().getBody(RegisterUser.class);

我得到的注册用户对象。一切工作正常。
问题是,我想骆驼路由我的要求条件,为例如:

I get the register user object. Everything works fine. The problem is that I want camel to route my request conditionally, for e.g:

如果服务操作 RegisterUser 我想将消息路由到我的具体豆,如果服务操作 UpdateUser两个我想将消息路由到其他的bean。

If the service operation is RegisterUser I want to route the message to my specific bean and if the service operation is UpdateUser I want to route the message to the other bean.

我曾尝试使用骆驼XPATH,但它不似乎是工作。

I have tried to use camel xPath, but it not seems to be working.

<camel:route id="myRoute">
    <camel:from uri="cxf:bean:myListenerEndpoint?dataFormat=POJO&amp;synchronous=true" />  
    <camel:choice>
        <camel:when>
            <camel:xpath>
                //RegisterUser
            </camel:xpath>
            <camel:bean ref="processor" method="processMessage"/>
            <camel:to uri="xslt:file:resources/service/2.0.0/UserRegistration.xsl"/>
        </camel:when>
    </camel:choice>                        
    <camel:to uri="cxf:bean:myTargetEndpoint"/>
</camel:route>

我正在寻找如何骆驼设置路由到不同的目标,但没有发现任何东西。也许有人知道哪里可能有问题?

I was searching how to set up camel to route to the different targets but did not find anything. Maybe somebody knows where might be the problem?

推荐答案

将在邮件头中所需的操作的信息。

The information of the operation required will be in the header of the message.

您正在寻找的头被称为operationName

The header you are looking for is called 'operationName'

因此​​,这里有一个例子:

So here is an example :

<camelContext xmlns="http://camel.apache.org/schema/blueprint">
    <route id="example">
        <from uri="cxf:bean:myListenerEndpoint?dataFormat=POJO&amp;synchronous=true" />
        <log message="The expected operation is :: ${headers.operationName}" />
        <choice>
            <when>
                <simple>${headers.operationName} == 'RegisterUser'</simple>
                    <bean ref="processor" method="processMessage"/>
                <to uri="xslt:file:resources/service/2.0.0/UserRegistration.xsl"/>
            </when>
            <when>
                <simple>${headers.operationName} == 'UpdateUser'</simple>
                <!-- Do the update user logic here -->
                <bean ref="processor" method="updateUser" />
            </when>
        </choice>
    <to uri="cxf:bean:myTargetEndpoint"/>
    </route>
</camelContext> 

(注意例子是使用Apache白羊蓝图 - 但它会比命名空间相同为弹簧,其它)

(Note the example is using apache aries blueprint - but it will be identical for spring, other than the namespace)

这篇关于Apache的骆驼条件路由的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆