1

ファイルを行ごとに解析する必要があります。各行は、スプリッターコンポーネントを使用して個別に処理されます。すべての行が処理された後、ファイルを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&amp;readLock=${idt.proxy.real.card.parser.readLock}&amp;readLockCheckInterval=${idt.proxy.real.card.parser.readLockCheckInterval}&amp;readLockTimeout=${idt.proxy.real.card.parser.readLockTimeout}&amp;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ブロックで囲んでみましたが、役に立ちませんでした。

4

2 に答える 2

3

スプリッター内にtry..catchブロックを配置する必要があります。スプリッター内で実行されるロジックで例外が発生すると思います。

別の方法は、onExceptionを使用して例外を処理することです。

于 2012-09-28T07:07:10.360 に答える
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-エラー処理のその他の方法について説明しています。

于 2016-12-27T21:22:10.437 に答える