我实际上有一个包含3个步骤的过程:
测试时所有这些都正常工作,但是后来,我看到当处理大型CSV时,第2步失败。
有关该步骤2的详细信息
步骤2和3的路线
<route id="tozip">
<from uri="file:{{path}}/out?readLock=changed"/>
<setBody>
<simple>resource:file:{{path}}/conf/HeadTxtFoot.txt</simple>
</setBody>
<log message="Compressing message..." loggingLevel="INFO" />
<marshal ref="gzip" />
<log message="Sending ${file:name}.gz..." loggingLevel="INFO" />
<to uri="file:{{path}}/tosend/?fileName=${file:name}.gz" />
</route>
HeadTxtFoot.txt
<tag>
<informationDate>${headers.date}</informationDate>
<files>
${body}
</files>
<tag>
我最近在此路由中输入了350Mb的文件,并且出现此错误
Message History
---------------------------------------------------------------------------------------------------------------------------------------
RouteId ProcessorId Processor Elapsed (ms)
[tozip ] [tozip ] [file:///u01?readLock=changed ] [ 459]
[tozip ] [setBody2 ] [setBody[simple{resource:file:{{path}}/conf/HeadTxtFoot.txt}] ] [ 459]
Stacktrace
---------------------------------------------------------------------------------------------------------------------------------------
org.apache.camel.TypeConversionException: Error during type conversion from type: java.lang.String to the required type: java.lang.String with value [Body is file based: GenericFile[/u01/file.xml]] due java.lang.OutOfMemoryError: Java heap space
at org.apache.camel.impl.converter.BaseTypeConverterRegistry.createTypeConversionException(BaseTypeConverterRegistry.java:667)
at org.apache.camel.impl.converter.BaseTypeConverterRegistry.convertTo(BaseTypeConverterRegistry.java:158)
...
Caused by: org.apache.camel.RuntimeCamelException: java.lang.OutOfMemoryError: Java heap space
at org.apache.camel.util.ObjectHelper.wrapRuntimeCamelException(ObjectHelper.java:1831)
at org.apache.camel.util.ObjectHelper.invokeMethod(ObjectHelper.java:1410)
at org.apache.camel.impl.converter.StaticMethodTypeConverter.convertTo(StaticMethodTypeConverter.java:59)
at org.apache.camel.impl.converter.BaseTypeConverterRegistry.doConvertTo(BaseTypeConverterRegistry.java:326)
at org.apache.camel.impl.converter.BaseTypeConverterRegistry.convertTo(BaseTypeConverterRegistry.java:141)
... 22 more
Caused by: java.lang.OutOfMemoryError: Java heap space
没有setBody / Simple的相同路线可以正常工作
现在,我的问题是:在文件中添加行以避免错误的最佳方法是什么?
要解决:请勿将整个文件读入内存。而是使用“流”流式传输文件内容。为此,您可以在路线上设置streaming参数