ridermule
ridermule

Reputation: 143

Mule choice route depending on the payload of the message

I am new to MULE. I am trying to create a mule flow to route to different endpoints depending on the content of the XML payload. For example, if the payload's root element is Aa, I want to route the message to Queue A. Otherwise, it should go to Queue B. Can anyone give me some pointers about how to accomplish this?

So, far, I tried this:

<choice doc:name="Choice">
        <when expression="message.getpayload contains 'Aa'" evaluator="string">
            <processor-chain>
                <jms:outbound-endpoint queue="A" connector-ref="Active_MQ" doc:name="JMS"/>
            </processor-chain>
        </when>
        <otherwise>
            <processor-chain>
                <jms:outbound-endpoint queue="B" connector-ref="Active_MQ" doc:name="JMS"/>
            </processor-chain>
        </otherwise>
    </choice>

But everything is going to Queue A and so my choice expression is not working. Any help would be appreciated.

thanks!!!

Upvotes: 0

Views: 2179

Answers (1)

Daniel
Daniel

Reputation: 958

When working with XML data is better to use XPath to evaluate this kind of conditions.

<choice doc:name="Choice">
    <when expression="/Aa" evaluator="xpath">
        <processor-chain>
            <jms:outbound-endpoint queue="A" connector-ref="Active_MQ" doc:name="JMS"/>
        </processor-chain>
    </when>
    <otherwise>
        <processor-chain>
            <jms:outbound-endpoint queue="B" connector-ref="Active_MQ" doc:name="JMS"/>
        </processor-chain>
    </otherwise>
</choice>

HTH

Upvotes: 4

Related Questions