Camel 如何锁定正在写入的文件,使其他消费者无法消费

mzmfm0qo  于 8个月前  发布在  Apache
关注(0)|答案(2)|浏览(96)

我正在使用camel替换文件中的数据(它是400 MB的大文件),我面临着其他消费者拾取文件的问题,即使文件正在使用(它处于写入模式)。
在Camel中有没有一种方法可以锁定处于写入模式的文件,这样其他消费者/路由就不能消费了。一旦写入完成,它就应该消费。我试过readLocks,但到目前为止没有运气。

from("file://A").split().tokenize("\n", 999).streaming()
.log("Spliting::::::::::").unmarshal(csv).bean("transferDate", "enrich")
.marshal(csv).to("file://B?fileExist=Append");

from("file://B?delete=true").to("file://A"); // this route pick up file even the first route haven't finished writing file completely

字符串

jdzmm42g

jdzmm42g1#

您需要为Camel路由配置合适的文件阅读和写入选项,特别是需要为文件端点设置readLockreadLockLock选项。

from("file:/input-directory")
        .routeId("fileRoute")
        .to("file:/output-directory?readLock=changed&readLockTimeout=5000")
        .log("File processed: ${file:name}")
        .end();

字符串

j1dl9f46

j1dl9f462#

您可以使用done files。如果您在文件消费者上配置它们,它会忽略所有文件,直到真实的文件旁边有一个done(或标记)文件。
您还可以配置文件生产者来创建完成文件。
请参阅Camel Docs for File component,然后转到Using done files一章。

相关问题