1

我的要求似乎很简单。我需要轮询单个目录并根据我需要的输入文件的文件名;

a) 设置标头值 b) 将消息定向到特定的 JMS 队列

我已经尝试了几种不同的方法来实现这一点,但根据文档,followng 应该可以工作.. 显然对我来说不是......

        <from uri="file:[some input directory]"/>

        <when>
            <simple>${file:name} contains 'new'</simple>
            <setHeader headerName="messageType">
                <constant>NEW</constant>
            </setHeader>
            <to uri="jmsbroker:queue:[queue for new items]"/>
        </when>
        <when>
            <simple>${file:name} contains 'amend'</simple>
            <setHeader headerName="messageType">
                <constant>AMEND</constant>
            </setHeader>
            <to uri="jmsbroker:queue:[queue for amended items]"/>
        </when>
        <when>
            <simple>${file:name} contains 'other'</simple>
            <setHeader headerName="messageType">
                <constant>OTHER</constant>
            </setHeader>
            <to uri="jmsbroker:queue:[queue for other]"/>
        </when>
        <otherwise>
            <bean ref="deadLetterErrorHandler"/>
        </otherwise>

    </route> 

非常感谢任何帮助。

问候,安迪

4

1 回答 1

2

您缺少条件(请参阅基于内容<choice>路由器文档<when>

此外,您的<otherwise>部分应该只是路由到错误队列或引发异常......

尝试这样的事情......

    <route>
        <from uri="file:/tmp/inbox"/>
        <choice>
            <when>
                <simple>${file:name} contains 'new'</simple>
                <setHeader headerName="messageType">
                    <constant>NEW</constant>
                </setHeader>
                <to uri="jmsbroker:queue:newItems"/>
            </when>
            <otherwise>
                <to uri="jmsbroker:queue:errorQueue"/>
            </otherwise>
        </choice>
    </route>
于 2012-04-12T16:28:56.333 回答