2012-07-27 24 views
7

मेरे पास एक सेवा है जिसमें दो ऑपरेशन हैं।अपाचे कैमल सशर्त रूटिंग

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

मैं एक ऊंट भगदड़ की है। सब कुछ ठीक काम करता है। समस्या यह है कि मैं मार्ग के लिए ऊंट चाहते मेरे अनुरोध को सशर्त, उदाहरण के लिए है:

तो सेवा आपरेशन RegisterUser मैं अपने विशिष्ट सेम के लिए संदेश रूट करना चाहते है और यदि सेवा आपरेशन UpdateUser है मैं संदेश रूट करना चाहते अन्य बीन के लिए।

मैंने ऊंट 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> 

मैं खोज रहा था कि विभिन्न लक्ष्यों के मार्ग पर ऊंट कैसे स्थापित करें लेकिन कुछ भी नहीं मिला। शायद कोई जानता है कि समस्या कहां हो सकती है?

उत्तर

14

संचालन आवश्यक संदेश के शीर्षक में हो जाएगा की जानकारी।

हैडर आप देख रहे हैं '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> 

(नोट उदाहरण अपाचे मेष खाका उपयोग कर रहा है - लेकिन यह वसंत के लिए एक जैसे होंगे नामस्थान के अलावा)

+0

यह मेरे लिए बहुत अच्छा काम करता है। वास्तव में मुझे क्या चाहिए। धन्यवाद! :) –

4

इस के लिए xpath के बजाय camel-simple अभिव्यक्ति का उपयोग करते कोशिश ...

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