2012-04-12 63 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>