2014-05-20 18 views
0

我的要求是每隔幾分鐘輪詢一次數據庫並獲得一個sql。因此,我的代碼是找到的元素'simple'開頭的內容無效。駱駝問題

<camel:route> 

     <camel:from uri="timer:dataRetrieve?period=5s"/> 

      <camel:to uri="sql:select output_obj,create_dt,destination_type from dbo.gcas_events_test where process_sw = 'N' order by create_dt desc" /> 


     </camel:route> 

我期待從我的數據集中的3個字段。我想看看destination_type ='SEC',那麼它必須去不同的路線。

所以我想出了。

<camel:route> 

       <camel:from uri="timer:dataRetrieve?period=5s"/> 

        <camel:to uri="sql:select output_obj,create_dt,destination_type from dbo.gcas_events_test where process_sw = 'N' order by create_dt desc" /> 
       <camel:choice> 
         <camel:when> 
          <simple>${body.destination_type}='SEC'</simple> 
          <camel:to uri="foo" /> 
         </camel:when> 

        </camel:choice> 

       </camel:route> 

而且它在簡單的標籤拋出一個錯誤。與ognl類似的問題也是如此。我在這裏做錯了什麼? ${body.destination_type}='SEC'也會工作嗎? (假設我在數據集中有這個值)。

回答

1

根據Camel doc,如果配置不同,select語句的輸出爲List<Map<String, Object>>

${body[0][destination_type]} 

路由定義應該如下(使用==,而不是一個簡單的=):

<camel:route> 
    <camel:from uri="timer:dataRetrieve?period=5s"/> 
    <camel:to uri="sql:select output_obj,create_dt,destination_type from dbo.gcas_events_test where process_sw = 'N' order by create_dt desc" /> 
    <camel:choice> 
     <camel:when> 
      <camel:simple>${body[0][destination_type]} == 'SEC'</simple> 
      <camel:to uri="foo" /> 
     </camel:when> 
    </camel:choice> 
</camel:route> 

如果在你的情況,在結果集中找到的第一個destination_type可以如下訪問結果集的每個記錄應逐一處理,然後您可以使用一個splitter

<camel:route> 
    <camel:from uri="timer:dataRetrieve?period=5s"/> 
    <camel:to uri="sql:select output_obj,create_dt,destination_type from dbo.gcas_events_test where process_sw = 'N' order by create_dt desc" /> 
    <camel:split> 
     <camel:simple>${body}</camel:simple> 
     <camel:choice> 
      <camel:when> 
       <camel:simple>${body[destination_type]} == 'SEC'</simple> 
       <camel:to uri="foo" /> 
      </camel:when> 
     </camel:choice> 
    </camel:split> 
</camel:route> 
+0

這是有效的。非常感謝。 – Krishna

相關問題