Вопрос

У меня есть услуга, которая имеет две операции.

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

в моем процессоре Bean, когда я указываю:

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

Я получаю объект пользователя регистра.Все работает нормально. Проблема в том, что я хочу, чтобы верблюд покончить по условному запросу, для E.G:

Если операция службы является RegisterUser, я хочу направить сообщение в мой конкретный боб, и если операция службы является UpdateUser, я хочу направить сообщение на другой BEAL.

Я пытался использовать верблюда XPath, но, похоже, работает.

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

Я искал, как настроить верблюда на пути к различным целям, но ничего не нашел.Может быть, кто-то знает, где может быть проблема?

Это было полезно?

Решение

Информация о необходимой операции будет в заголовке сообщения.

Заголовок, который вы ищете, называется «ExperialName»

Так вот пример:

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

(обратите внимание на пример с использованием avache aries blueprint - но он будет идентичен для весны, кроме пространства имен)

Другие советы

Попробуйте использовать Camel-Simple выражения вместо XPath для этого ...

<when><simple>${body} is 'com.RegisterUser'</simple><to uri="..."/></when>
.

Весной XML маршрут В моем случае я использую входящую мочку EP. Я проверяю параметр по запросу. Приворот URL http:// localhost: 8080 / srv? Alg= 1

    <choice id="_choice1">
    <when id="_when1">
        <simple>${in.header.alg} == '1'</simple>
        <log id="_log10" message="LOG ALG 1"/>
    </when>
    ...
    <otherwise id="_otherwise1">
        <setFaultBody id="_setFaultBody1">
            <constant>Return message about ERROR</constant>
            </setFaultBody>
    </otherwise>
</choice>
.

final CamelContext context = exchange.getContext();
if (isAlive) {
    context.startRoute("table-reader-route");
    log.info("starting dailycase route= " + response);
} else {
    context.stopRoute("table-reader-route");
    log.info("stoping dailycase route= " + response);
}
.
Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top