Apache Camel条件路由
我有一项服务有两项操作。
RegisterUserUpdateUser
我有骆驼大溃败:
<camel:route id="myRoute">    <camel:from uri="cxf:bean:myListenerEndpoint?dataFormat=POJO&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>
在我的处理器bean中,当我指定时:
RegisterUser registerUser = exchange.getIn().getBody(RegisterUser.class);我得到了注册用户对象。一切正常。问题是我希望骆驼有条件地路由我的请求,例如:
如果服务操作是RegisterUser我要将消息路由到我的特定bean,并且如果服务操作是UpdateUser我要将消息路由到另一个bean。
我尝试使用骆驼xPath,但似乎无法正常工作。
<camel:route id="myRoute">    <camel:from uri="cxf:bean:myListenerEndpoint?dataFormat=POJO&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>
我正在搜索如何设置骆驼以路由到不同的目标,但没有找到任何东西。也许有人知道问题可能出在哪里?
回答:
所需操作的信息将在消息的标题中。
您要查找的标题称为“ operationName”
所以这是一个例子:
<camelContext xmlns="http://camel.apache.org/schema/blueprint">    <route id="example">
        <from uri="cxf:bean:myListenerEndpoint?dataFormat=POJO&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 aries蓝图-但除了名称空间外,它对于spring来说是相同的)
以上是 Apache Camel条件路由 的全部内容, 来源链接: utcz.com/qa/412094.html








