Apache camel 使用多个线程时在camel中丢失文件

Apache camel 使用多个线程时在camel中丢失文件,apache-camel,Apache Camel,我正在使用ApacheCamel 2.11.1 有这样的路线: from("file:///somewhere/"). threads(20). to("direct:process") 有时我会遇到这样的异常:org.apache.camel.InvalidPayloadException和消息 No body available of type: java.io.InputStream but has value: GenericFile[/somewhere/file.txt] of

我正在使用ApacheCamel 2.11.1

有这样的路线:

from("file:///somewhere/").
 threads(20).
 to("direct:process")
有时我会遇到这样的异常:
org.apache.camel.InvalidPayloadException
和消息

No body available of type: java.io.InputStream but has value: GenericFile[/somewhere/file.txt] of type: 
org.apache.camel.component.file.GenericFile on: file.txt. Caused by: Error during type conversion from type: 
org.apache.camel.component.file.GenericFile to the required type: byte[] with value GenericFile[/somewhere/file.txt] 
due java.io.FileNotFoundException: /somewhere/file.txt (No such file or directory). 
因为我在目录中看到了很多.camelLock文件,所以我假设发生这种情况是因为很少有线程试图处理同一个文件。如何避免这种情况

更新1


试图使用scheduledExecutorService并删除
线程(20)
。似乎我丢失的文件越来越少,但仍然丢失。如何避免?任何帮助都将不胜感激

我遇到了类似的问题,我的问题是两个文件处理器从同一目录检索。结果:丢失所有文件

以下是场景:

  • Thread#1
    检索
    file1
    ,移动到
    process
    文件夹
  • Thread#2
    同时检索相同的文件:
    file1
    <代码>文件1已删除
  • Thread#2
    source
    目录中找不到
    file1
    ,重命名失败
  • Thread#1
    由于
    Thread#2
原因如下:

如果选中GenericFileProcessStrategySupport.renameFile方法,您将看到camel首先删除目标文件,然后将源文件重命名为目标文件。这就是为什么会出现上述情况


我不知道一个通用的解决方案,要么分离源-消费者关系,要么实现工作分发机制


既然您的线程生活在同一个JVM中,我建议您实现一个并发负载分配器。这将以并发方式一次为请求者提供1个文件名

您在direct:process中做什么?你在用什么操作系统?我在用Linux。实际上是在直接:过程只是读取文件和使用我的内部bean。得到相同的问题,一些文件被删除。我可以从日志中看到这个过程,但在任何错误、完成或当前文件夹中都找不到。完全测角是否使用noop=true以避免移动/删除文件?