문제

두 가지 작업이 있는 서비스가 있습니다.

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>

내 프로세서 빈에서 다음을 지정할 때:

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

나는 사용자 등록 개체를 얻습니다.모든 것이 잘 작동합니다.문제는 낙타가 내 요청을 조건부로 라우팅하기를 원한다는 것입니다. 예를 들면 다음과 같습니다.

서비스 운영이 다음과 같은 경우 RegisterUser 메시지를 내 특정 Bean으로 라우팅하고 싶습니다. 서비스 작업이 다음과 같은 경우 UpdateUser 메시지를 다른 Bean으로 라우팅하고 싶습니다.

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

낙타를 다른 대상으로 경로 설정하는 방법을 검색 중이었지만 아무 것도 찾지 못했습니다.어쩌면 문제가 어디에 있는지 아는 사람이 있을까요?

도움이 되었습니까?

해결책

필요한 작업 정보는 메시지 헤더에 있습니다.

찾고 있는 헤더는 'OperationName'입니다.

예는 다음과 같습니다.

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

(예제는 아파치 양자리 블루프린트를 사용하고 있지만 네임스페이스를 제외하면 Spring에서도 동일합니다.)

다른 팁

사용해 보세요 낙타처럼 단순한 이를 위해 xpath 대신 표현식을 사용하세요.

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

Spring XML 경로 제 경우에는 인바운드 Jetty 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