Apache camel 如何将结果集添加到camel中的csv文件
下面给出了我的xmlApache camel 如何将结果集添加到camel中的csv文件,apache-camel,marshalling,camel-sql,Apache Camel,Marshalling,Camel Sql,下面给出了我的xml <camelContext trace="false" xmlns="http://camel.apache.org/schema/spring"> <propertyPlaceholder id="placeholder" location="classpath:application.properties" /> <!--Route:1 for POLLUX Data Processing --> <
<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>
用于处理结果集的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;
}
公共类GlobalDataController{
List GlobalStationProcessedList=新建ArrayList();
List globalStationMap=new ArrayList();
@抑制警告(“未选中”)
公共列表进程GlobalData(Exchange)引发异常{
//System.out.println(“处理”+exchange.getIn().getBody());
globalStationMap=(列表)exchange.getIn().getBody();
GlobalStationProcessedList.addAll(globalStationMap);
返回GlobalStationProcessedList;
}
}
现在的问题是,路由1的数据被传输到csv文件中,该文件在数据库中具有精确的行数。但路由2中的任何数据都不会附加到csv文件中
我正在使用camel 2.16如果问题只出现在大量文件中(而不是文件格式),那么下面是解决方案:
<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&fileExist=Append" />
</route>
result.csv
对于下一个池,您可以根据当前时间设置另一个文件名。您是否尝试在sql组件上设置此参数 consumer.useIterator布尔值true Camel 2.11:SQL consumer only:如果为true,则在 投票将单独处理。如果为false,则整个 java.util.List的数据设置为IN body
尝试将此设置为false。这样,您应该将整个sql结果集放入一个列表中,然后将整个列表写入一个文件。您的解决方案成功了!!谢谢,但结果集在数据库中包含34000行,在文件中我只得到2000行。有任何限制吗?请注意,这似乎很奇怪,因为我认为没有任何默认限制。在camel中,获取结果集后,exchange标头CamelSqlRowCount的值是多少?是2000行还是34000行?您使用的是哪一个版本的Camel?您也可以尝试设置maxMessagesPerPoll=100000,如果您在Camel结果集中获得34000行,则可以查看所有34000行是否都已写入。Souciance,我已经用代码编辑了这个问题?我想问题出在一条路线上。你能阅读编辑的部分并帮助我吗?
<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&fileExist=Append" />
</route>