使用 Apache Camel 事务时如何回滚文件写入?
How to rollback file writes when using Apache Camel transaction?
我在带有两个管道的 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>
Apache Commons Transaction可以处理任何文件系统上的事务性读写操作。
您可以将处理器 com.***.upload.processors.ToFile
设置为在 process()
方法中以事务方式处理读写操作。
这个 SO Apache Transaction:write file transactionally - how to use resourceId 可以帮助在您的代码中集成通用事务。
我在带有两个管道的 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>
Apache Commons Transaction可以处理任何文件系统上的事务性读写操作。
您可以将处理器 com.***.upload.processors.ToFile
设置为在 process()
方法中以事务方式处理读写操作。
这个 SO Apache Transaction:write file transactionally - how to use resourceId 可以帮助在您的代码中集成通用事务。