Camel中的消息拆分

时间:2014-04-24 15:13:38

标签: xpath apache-camel

我正在尝试编写一个将列表的不同元素发送到不同队列的驼峰路由。

邮件正文将是一个包含2 xml的列表。例如:

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

现在,我需要发送消息的'Cat'部分,即cat1部分到queue1和xml的'Dog'部分,即Dog1到另一个队列?

这是我的路线,但不起作用:

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

关于我在这里做错了什么的想法?

1 个答案:

答案 0 :(得分:2)

首先,您必须使用,令牌拆分列表。其次,您必须使用XPath表达式解析XML部分并将消息发送到适当的JMS队列:

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