【问题标题】:Apache Camel route hangs when file is deleted during processing在处理过程中删除文件时,Apache Camel 路由挂起
【发布时间】:2019-05-20 19:31:42
【问题描述】:

我正在尝试构建的程序使用 Camel 2.18.5 使用 Windows 文件共享上的文件,而其他程序偶尔会在共享文件夹中添加/修改/删除文件。

构建一个简单的测试路线

        from("file:///C:/Temp/from?readLock=changed&readLockCheckInterval=10000&readLockTimeout=0")
            .routeId("SimpleFileRoute")
            .to("file:/C:/Temp/to");

然后在from文件夹中放置一个文件test.txt,等待路由生成test.txt.camelLock文件,然后在readLockCheckInterval过去之前手动删除test.txt,会导致路由无限挂起不抛出异常或处理任何其他文件。

"changed" 似乎是唯一适合这种情况的 readLock。

有没有办法让路由抛出异常,清理锁文件,继续消费文件?

编辑:似乎是路由的线程的堆栈跟踪是这样的:

Daemon Thread [Camel (camel-1) thread #2 - file:///C:/Temp/from] (Suspended)    
Thread.sleep(long) line: not available [native method]  
FileChangedExclusiveReadLockStrategy.sleep() line: 104  
FileChangedExclusiveReadLockStrategy.acquireExclusiveReadLock(GenericFileOperations<File>, GenericFile<File>, Exchange) line: 90    
GenericFileRenameProcessStrategy<T>(GenericFileProcessStrategySupport<T>).begin(GenericFileOperations<T>, GenericFileEndpoint<T>, Exchange, GenericFile<T>) line: 64    
GenericFileRenameProcessStrategy<T>.begin(GenericFileOperations<T>, GenericFileEndpoint<T>, Exchange, GenericFile<T>) line: 37  
FileConsumer(GenericFileConsumer<T>).processExchange(Exchange) line: 362    
FileConsumer(GenericFileConsumer<T>).processBatch(Queue<Object>) line: 223  
FileConsumer(GenericFileConsumer<T>).poll() line: 187   
FileConsumer(ScheduledPollConsumer).doRun() line: 174   
FileConsumer(ScheduledPollConsumer).run() line: 101 
Executors$RunnableAdapter<T>.call() line: 511   
ScheduledThreadPoolExecutor$ScheduledFutureTask<V>(FutureTask<V>).runAndReset() line: 308   
ScheduledThreadPoolExecutor$ScheduledFutureTask<V>.access$301(ScheduledThreadPoolExecutor$ScheduledFutureTask) line: 180    
ScheduledThreadPoolExecutor$ScheduledFutureTask<V>.run() line: 294  
RejectableScheduledThreadPoolExecutor(ThreadPoolExecutor).runWorker(ThreadPoolExecutor$Worker) line: 1142   
ThreadPoolExecutor$Worker.run() line: 617   
Thread.run() line: 745  

【问题讨论】:

  • 您可以尝试使用较新的 Camel 版本。你是说“改变”是你测试过的唯一一个有问题并导致它“挂起”的读锁。当它挂起时,您可以尝试进行线程转储并查看 Camel 挂在哪里吗?
  • 感谢您的提问。我很喜欢那个 Camel 版本,但升级一直在我的愿望清单上——也许明年。 “更改”是我测试过的唯一读锁 - 其他人似乎对我有其他潜在问题。遇到问题时,我使用暂停路由的堆栈跟踪更新了问题。
  • 啊,好吧,你的问题是你的读锁超时时间为 0,你不应该这样,因为它永远不会超时,所以将它设置为一些敏感值,比如 30-60 秒或其他时间检查间隔为 10 秒。

标签: java apache-camel


【解决方案1】:

好的,所以问题是您使用readLockTimeout=0,如果由于某种原因无法授予文件锁定,则它会阻止读取锁定超时。你不应该真的这样做(坏主意),所以将它设置为更高的超时值。

另一方面,我们也可以改进camel-core,在检查changed时检查文件是否仍然存在,如果文件不存在,也可以退出检查。

我已经为此记录了一张票:https://issues.apache.org/jira/browse/CAMEL-13025

【讨论】:

  • 谢谢,这解决了问题。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2016-09-29
  • 1970-01-01
相关资源
最近更新 更多