2016-01-13 75 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

你正在使用哪个版本的骆驼? –