gpt4 book ai didi

apache-camel - Apache Camel - 将大文件复制到使用者文件夹中

转载 作者:行者123 更新时间:2023-12-03 07:47:30 24 4
gpt4 key购买 nike

我有一条路线,期望将各种文件复制到传入文件夹中。该路线将继续将这些文件移动到临时文件夹中,在那里它将执行其他操作。路线如下:

       <route id="incoming" >
<from uri="file://my/path/incoming"/>
<to uri="file://my/path/incoming/temp"/>
</route>

问题是这些文件可能非常大。比方说 1Gb。为了将此文件复制到传入文件夹中,可能需要 10 秒钟。在这 10 秒内,消费者轮询目录并抛出异常,因为部分文件仍在复制。我可以使用什么解决方法?

我已经使用了 readLock 所有策略(主要改变了),但我得到了一个异常(exception):

(The process cannot access the file because it is being used by another process)

修改后的uri如下:

<from uri="file://my/file/path?readLockCheckInterval=3000&amp;readLock=changed"/>

还是没有运气

最佳答案

检查 File component 中的 readLock 选项

Used by consumer, to only poll the files if it has exclusive read-lock on the file (i.e. the file is not in-progress or being written). Camel will wait until the file lock is granted.

This option provides the build in strategies:

markerFile Camel creates a marker file (fileName.camelLock) and then holds a lock on it.

changed is using file length/modification timestamp to detect whether the file is currently being copied or not. Will at least use 1 sec. to determine this, so this option cannot consume files as fast as the others, but can be more reliable as the JDK IO API cannot always determine whether a file is currently being used by another process. The option readLockCheckInterval can be used to set the check frequency.

fileLock is for using java.nio.channels.FileLock. This approach should be avoided when accessing a remote file system via a mount/share unless that file system supports distributed file locks.

rename is for using a try to rename the file as a test if we can get exclusive read-lock.

关于apache-camel - Apache Camel - 将大文件复制到使用者文件夹中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25554167/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com