2016-11-08 4 views
1

2つのパイプラインを持つCamelのマルチキャストルートを使用しています。 1つのパイプラインがデータをデータベースに追加し、他のパイプラインはデータをファイルに書き込みます。 エラーやエラーが発生した場合の完全なプロセスをロールバックするための私の要求。 db挿入を正常にロールバックしましたが、ファイルに対して実行された書き込み操作をロールバックする方法が見つかりません。 誰かがロールバックプロセスで私を助けてくれますか?Apache Camelトランザクションを使用しているときにファイル書き込みをロールバックする方法はありますか?

<routeContext id="s1Route" xmlns="http://camel.apache.org/schema/spring"> 
    <route id="sRoute"> 
     <from uri="activemq:queue:{{s.queue}}" /> 
     <log message="Message received from myprocess queue is ${body}"></log> 
     <unmarshal ref="gsonUnmarshelling"></unmarshal> 
     <bean beanType="com.***.upload.***.GetMyBean" 
      method="process(com.**.upload.beans.MyEvenets,${exchange})" /> 
     <log message="Multicasting data ${body} to file system and database" /> 
     <multicast parallelProcessing="true"> 
      <pipeline> 
       <choice> 
        <when> 
         <simple>${properties:s.write.file} == true</simple> 
         <setHeader headerName="path"> 
          <simple>${properties:s.write.folder}</simple> 
         </setHeader> 
         <log message="Going to write to file : ${body}"></log> 
         <bean beanType="com.***.upload.processors.ToFile" 
          method="process(${exchange},com.***.upload.beans.MyFile)" /> 
         <to uri="file://?fileExist=Append"></to> 
        </when> 
       </choice> 
      </pipeline> 
      <pipeline> 
       <log message="Going to insert in database"></log> 
       <transform> 
        <method ref="insertBean" method="MyBatchInsertion"></method> 
       </transform> 
       <choice> 
        <when> 
         <simple>${in.header.myCount} == ${properties:batch.size}</simple> 
         <to uri="sql:{{sql.my.insertBatch}}?batch=true"></to> 
         <log message="Inserted rows ${body}"></log> 
        </when> 
       </choice> 
      </pipeline> 
     </multicast> 
    </route> 
</routeContext> 

答えて

0

Apache Commons Transactionがトランザクションの読み取りに対処し、任意のファイルシステムの操作を書き込むことができます。 はここに私のルートコンテキストです。

com.***.upload.processors.ToFileは、process()メソッドで読み取りと書き込みの処理をトランザクション処理するように設定できます。

このSO Apache Transaction:write file transactionally - how to use resourceIdは、コード内での共通トランザクションの統合を支援します。

関連する問題