2016-11-08 92 views
1

我在两条管道中使用骆驼的多播路由。 一个管道将数据添加到数据库中,另一个管道对文件执行一些写入操作。 我的要求是在出现故障或任何错误时回滚整个过程。 我已成功回滚数据库插入,但无法找到任何方式来回滚文件上完成的写入操作。 任何人都可以帮助我回滚过程。 这里是我的路由上下文:如何在使用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> 

回答