2016-01-13 72 views
0

我的XML如下如何添加結果集爲CSV文件中的駱駝

<camelContext trace="false" xmlns="http://camel.apache.org/schema/spring"> 

    <propertyPlaceholder id="placeholder" location="classpath:application.properties" /> 

    <!--Route:1 for POLLUX Data Processing --> 

<route id="processPolluxData-Route" startupOrder="1"> 
<from uri="{{POLLUX_INPUT_PATH}}?noop=true"/> 
    <unmarshal ref="csvBindyDataformatForPolluxData"/> 
    <camel:bean ref="polluxDataController" method="processPolluxData"/> 
    <camel:log message="Line:${body}" loggingLevel="INFO"/> 
<to uri="sqlComponent:{{sql.insertPolluxData}}?batch=true" /> 
</route> 

    <!-- Route:2 for RSI Data Processing --> 

<route id="processRsiData-Route" startupOrder="2"> 
<from uri="{{RSI_INPUT_PATH}}?noop=true"/> 
    <unmarshal ref="csvBindyDataformatForRsiData"/> 
    <camel:bean ref="rsiDataController" method="processRsiData"/> 
    <camel:log message="Line:${body}" loggingLevel="INFO"/> 
<to uri="sqlComponent:{{sql.insertRsiData}}?batch=true" /> 
</route> 

    <!-- Route for Global Data Processing --> 
    <route id="processGlobalData-Route" > 
    <from uri="sqlComponent:{{sql.selectOrder}}?consumer.useIterator=false" /> 
     <camel:bean ref="globalDataController" method="processGlobalData" /> 
     <marshal> 
      <csv delimiter=","/> 
     </marshal> 
     <log message="${body}" /> 
    <setHeader headerName="camelFilename"> 
     <constant>result.csv</constant> 
    </setHeader> 
    <to uri="{{GLOBAL_OUTPUT_PATH}}?fileExist=Append" /> 
</route> 

我的SQL語句中給出的

sql.selectOrder=select STID,CLLTR,SOURCE from GSI_DEVL.POLLUX_DATA 

bean類進行處理的結果集是

public class GlobalDataController { 

List<Map<String, Object>> globalStationProccessedList = new ArrayList<Map<String, Object>>(); 
List<Map<String, Object>> globalStationMap = new ArrayList<Map<String, Object>>(); 

@SuppressWarnings("unchecked") 
public List<Map<String, Object>> processGlobalData(Exchange exchange) throws Exception { 

    // System.out.println("Processing " + exchange.getIn().getBody()); 

    globalStationMap = (List<Map<String, Object>>) exchange.getIn().getBody(); 
    globalStationProccessedList.addAll(globalStationMap); 

    return globalStationProccessedList; 
} 

}

現在的問題是1個線數據transffered到CSV文件與database.But行的確切數目在路由2沒有數據追加到CSV文件 我使用駱駝2.16

回答

0

如果問題只在大量的文件(而不是在文件格式),然後在這裏是解決方案:

<route id="processOrder-route"> 
    <from uri="sqlComponent:{{sql.selectOrder}}"/> 
    <camel:bean ref="controllerformarshalling" method="processGlobalData" /> 
    <marshal > 
    <csv delimiter="," useMaps="true" > </csv> 
    </marshal> 
    <log message="${body}"/> 
    <setHeader headerName="CamelFileName"> 
     <constant>result.csv</constant> 
    </setHeader> 
    <to uri="file://D://cameltest//output&amp;fileExist=Append" /> 
    </route> 

對於您可以設置另外一個文件名,根據當前時間,也許下一池。

0

您是否嘗試過在sql組件上設置此參數?

consumer.useIterator邏輯真 駱駝2.11:SQL消費者只:如果爲真時 投票將單獨處理的每一行返回。如果爲false,則將整個數據的java.util.List設置爲IN主體。

嘗試將其設置爲false。這樣你應該將整個sql結果集放到一個列表中,然後將整個列表寫入一個文件。

+0

您的解決方案工作!謝謝 但結果集在數據庫中包含34000行,在文件中我只得到2000行。是否有任何限制? 請幫忙 –

+0

似乎很奇怪,因爲我不認爲有任何默認限制。在camel中,獲取結果集後,交換頭文件CamelSqlRowCount的值是多少?它是2000還是34000? –

+0

你正在使用哪個版本的駱駝? –