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

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

问题描述

我正在编写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="\r\n"/>

            <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="\r\n4000"/>

            [...]

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

        </split>

    </route>

我正在尝试确保路由Init生成的文件不会被路由End占用,直到Init完成对第一个文件的处理为止.

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.

有什么想法吗?

谢谢!

推荐答案

使用已完成的文件

Use done file

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

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.

有关更多详细信息,请阅读第2部分使用骆驼文件组件的'完成的'文件"

For more details, please read Section "Using 'done' Files" of Camel File Component

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

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