Question

I am trying to write a camel route which would send different elements of a list to different queues.

The message body would be a list with 2 xml's. For example:

<Cat>
<Name>Cat1</Name>
</Cat>,
<Dog>
<Name>Dog1</Name>
</Dog>

Now, I need to send the 'Cat' part of the message i.e. Cat1 part to queue1 and the 'Dog' part of xml i.e. Dog1 to a different queue?

This is the route that I have, but is not working:

<route>
    <from uri="jms:queue:InQueue" />        
    <choice>
        <when>
            <simple>${in.body} regex 'Cat'</simple>
            <to uri="jms:queue:CatQueue" />
        </when>
        <when>
            <simple>${in.body} regex 'Dog'</simple>
            <to uri="jms:queue:DogQueue" />
        </when>
    </choice>
</route>

Any ideas on what am i doing wrong here?

Was it helpful?

Solution

First, you have to split the list using the , token. Second, you have to parse the XML parts using XPath expressions and send the messages to the appropriate JMS queues:

<route>
    <from uri="jms:queue:InQueue" />
    <split>
        <tokenize token=","/>
        <log message="Working on split: ${body}" />
        <choice>
            <when>
                <xpath>/Cat</xpath>
                <to uri="jms:queue:CatQueue" />
            </when>
            <when>
                <xpath>/Dog</xpath>
                <to uri="jms:queue:DogQueue" />
            </when>
        </choice>
    </split>
</route>
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top