我需要按行解析文件。每行使用分离器组件分开处理。处理完所有行后,我需要将文件复制到done_folder。如果正确处理所有行,则一切正常。但是如果有不正确的行,那么我会收到有关回滚的以下警告,并且文件不会复制到done_folder 警告:
WARN (Camel (com.company.realcardparser) thread #0 - file://project/src/test/resources/working_folder) [GenericFileOnCompletion] Rollback file strategy: org.apache.camel.component.file.strategy.GenericFileDeleteProcessStrategy@41a7d9e7 for file: GenericFile[237file09062012-qa.csv]
我的骆驼配置:
<camelContext id="com.company.realcardparser" xmlns="http://camel.apache.org/schema/spring" trace="true">
<routeContextRef ref="idtProxyRoute"/>
<endpoint id="fileParserInputEndPoint" uri="file:${idt.proxy.real.card.parser.folder.test.input}?delete=true&readLock=${idt.proxy.real.card.parser.readLock}&readLockCheckInterval=${idt.proxy.real.card.parser.readLockCheckInterval}&readLockTimeout=${idt.proxy.real.card.parser.readLockTimeout}&delay=${idt.proxy.real.card.parser.delay}"/>
<endpoint id="fileParserOutputEndPoint" uri="file:${idt.proxy.real.card.parser.folder.test.output}"/>
<endpoint id="fileParserOutputFailedEndPoint" uri="file:${idt.proxy.real.card.parser.folder.test.output.failed}"/>
</camelContext>
<bean id="idtTxRequired" class="org.apache.camel.spring.spi.SpringTransactionPolicy">
<property name="transactionManager" ref="transactionManager"/>
<property name="propagationBehaviorName" value="PROPAGATION_REQUIRES_NEW"/>
</bean>
<routeContext id="idtProxyRoute" xmlns="http://camel.apache.org/schema/spring">
<route id="idtRealCardParserRoute">
<from ref="fileParserInputEndPoint"/>
<transacted ref="idtTxRequired"/>
<split>
<method bean="realCardParser" method="handle"/>
<to uri="bean:realCardFinalizer"/>
</split>
<to ref="fileParserOutputEndPoint"/>
</route>
</routeContext>
如何让骆驼忽略异常?我尝试用try / catch块包围分割器,但它没有帮助。
答案 0 :(得分:3)
onException(Exception.class)
.process(new Processor() {
@Override
public void process(Exchange exchange) throws Exception {
// place to add logic to handle exception
Throwable caught = exchange.getProperty(Exchange.EXCEPTION_CAUGHT,
Throwable.class);
logger.error("FATAL ERROR - ", caught);
}
})
.handled(true); // if I don't give handled(true), it will keep reprocessing the file again and again.
from("file:" + pathToFile + "?noop=true")
// rest of the route
http://camel.apache.org/exception-clause.html - 解释更多错误处理方法。
答案 1 :(得分:2)
您需要将try .. catch块放在拆分器中。我假设异常发生在分割器内部执行的逻辑中。
另一种方法是使用onException并处理异常。