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>