在骆驼上附加数据时锁定文件 [英] Locking file while appending data on Camel

查看:32
本文介绍了在骆驼上附加数据时锁定文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在编写 2 条路由来处理目录中的文件,这些文件可以有任何名称,但我需要 2 条路由,因为我需要一些复杂的处理.

I am writing 2 routes to process a files in a directory, those files could have any name, but I need 2 routes as I need some complex processing.

第一条路线:

<route id="Init">
        <from uri="file:{{file.path}}?move=.done&amp;moveFailed=.error&amp;readLock=changed&amp;readLockCheckInterval=1500&amp;charset=UTF-8"/>
        <transacted/>

        <split streaming="true" stopOnException="true" shareUnitOfWork="true" parallelProcessing="false">
            <tokenize token="
"/>

            <choice>
                <when>
                    <simple>${body.substring(0,4)} == 4000</simple>

                    [...]

                    <to uri="file:{{file.path}}/tmp?fileName=${date:now:yyyyMMddss}.txt&amp;fileExist=append&amp;charset=UTF-8"/>
                </when>

                <when>
                    <simple>${body.substring(0,4)} == 4002</simple>

                    [...]

                    <to uri="file:{{file.path}}/tmp?fileName=${date:now:yyyyMMddss}.txt&amp;fileExist=append&amp;charset=UTF-8"/>
                </when>
            </choice>

        </split>

    </route>

第二个路由,它消费第一个路由产生的文件:

Second route, which consumes the file produced by the first route:

<route id="End">
        <from uri="file:{{file.path}}/tmp?delete=true&amp;moveFailed=.error&amp;readLock=changed&amp;readLockCheckInterval=1500&amp;charset=UTF-8"/>
        <transacted/>

        <split streaming="true" stopOnException="true" shareUnitOfWork="true" parallelProcessing="false">
            <tokenize token="
4000"/>

            [...]

            <to uri="[...]"/>

        </split>

    </route>

我正在尝试确保在 Init 完成处理第一个文件之前,路由 Init 生成的文件不会被路由 End 消耗.

I am trying to make sure file produced by route Init won't be consumed by route End until the Init has finished processing the first file.

我猜想使用临时文件扩展名,然后在第二条路线上使用排除,但它不适用于 fileExists.

I guessed using a temp file extension, and then using an exlude on the second route, but it doesn't work with fileExists.

有什么想法吗?

谢谢!

推荐答案

使用完成的文件

您需要一种机制来确保第二条路由仅使用已被第一条路由完全处理的文件.

You need a mechanism to make sure the second route only consume file that have been completely processed by first route.

一个简单的方法是让第一个路由发出一个完成的文件作为信号告诉第二个路由该文件已经处理完成并准备好接收.

A simple method is to let first route emit a done file as a signal to tell second route that the file has been processed completed and is ready to pickup.

要使用完成文件,您可以在处理完成时在第一个路由中添加 doneFileName 参数,并使用相同的文件名模式添加第二个路由.

To use done file, you could add doneFileName parameter in first route when process completed and also add in the second route using same filename pattern.

更多详情,请阅读骆驼文件组件的使用'done'文件"部分

这篇关于在骆驼上附加数据时锁定文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆