2012-04-12 65 views
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> 

任何帮助非常赞赏。

问候, 安迪

回答

2

你缺少<choice>周围<when>条件语句(见content based router docs

也,你<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>