2014-01-21 140 views
0

我用駱駝(2.11.0)至嘗試,實現了以下功能:駱駝文件處理

  • 如果文件存在於某一位置,將它複製到另一個位置,然後開始處理它
  • 如果沒有這樣的文件存在,那麼我不希望文件消費者/輪詢阻止;我只想要繼續處理direct:cleanup路線

我只希望文件被輪詢一次!

這裏是我到目前爲止(使用Spring XML):

<camelContext id="my-camel-context" xmlns="http://camel.apache.org/schema/spring"> 
    <route id="my-route 
     <from uri="file:///home/myUser/myApp/fizz?include=buzz_.*txt"/> 

     <choice> 
      <when> 
       <!-- If the body is empty/NULL, then there was no file. Send to cleanup route. --> 
       <simple>${body} == null</simple> 
       <to uri="direct:cleanup" /> 
      </when> 

      <otherwise> 
       <!-- Otherwise we have a file. Copy it to the parent directory, and then continue processing. --> 
       <to uri="file:///home/myUser/myApp" /> 
      </otherwise> 
     </choice> 

     <!-- We should only get here if a file existed and we've already copied it to the parent directory. --> 
     <to uri="bean:shouldOnlyGetHereIfFileExists?method=doSomething" /> 
    </route> 

    <!-- 
     Other routes defined down here, including one with a "direct:cleanup" endpoint. 
    --> 
</camelContext> 

通過上述配置,如果在/home/myUser/myApp/fizz沒有文件,那麼駱駝只是等待/塊,直到有一個。相反,我想讓它放棄並轉向direct:cleanup

如果有一個文件,我看到它在shouldOnlyGetHereIfFileExists bean中得到處理,但我沒有看到它被複制到/home/myUser/myApp;所以就好像<otherwise>元素被完全忽略/忽略!

任何想法?提前致謝!

回答

1

試試這個設置和調整您的輪詢間隔,以滿足:

Camel File Component文檔:

sendEmptyMessageWhenIdle

默認=假

駱駝2.9:如果輪詢消費者做不輪詢任何文件,您可以啓用此選項來發送空的消息(無主體)。

關於寫入文件,請在<otherwise>內部添加一條日誌語句以確保它正在執行。如果是這樣,檢查文件/文件夾的權限等。

祝你好運。

+0

感謝@vikingsteve - 我給你一個+1,但我沒有足夠的代表。我感覺不好,有一件我忘記提及的重要部分:**我只想要路線輪詢文件一次。**你對'sendEmptyMessageWhenIdle'的建議確實有效,但是路線不斷輪詢,一遍一遍地重現一個文件。關於如何配置Camel只能輪詢一次的任何想法?再次感謝! – AdjustingForInflation

+0

那麼還有一個'delay'選項 - 你可以嘗試將它設置爲0或-1,或者一些非常大的值,然後看看會發生什麼。否則,在第一次執行路由期間,您可以使用'controlbus'來停止路由。 – vikingsteve

+0

看起來像延遲不能<= 0,但你可以嘗試一個非常高的值。否則,拋出異常(你以某種方式處理)也可能會停止路由。 – vikingsteve

0

這是很老了,但如果任何人發現這一點,你可以查詢只 一次