【问题标题】:File component(Apache camel) delete=true parameter not working in windows文件组件(Apache camel)delete=true 参数在 Windows 中不起作用
【发布时间】:2018-04-27 17:31:12
【问题描述】:

Apache Camel File 组件在 Windows7 中无法正常运行,而在 Linux 中运行没有任何问题。

我的要求:

文件处理后,必须从目录中删除文件。在 Windows 中,由于 .camelLock 文件无法正确删除。

多次尝试后,只有 Apache camel 可以从目录中删除文件。如果尝试无法从目录中删除文件,则会引发异常。

如果我在目录中只有一个文件,它可以正常工作,但如果我有多个文件,那么它会抛出异常。

应用环境:

我在 Tomcat 服务器中部署了 Apache camel 应用程序。

Apache Camel 版本:2.17.1

阿帕奇骆驼路线:

 <from uri="file:///var/opt/irs/message?delete=true" />
 <to uri="direct:file.storage.original" />

在 Windows 中,我收到以下错误:

1|2017-11-14 17:56:34,828|11-01-41|默认|警告
|是||o.a.c.c.f.GenericFileOnCompletion|file.analysis.input|错误 在提交期间。交换 [ID-51741-1510678404569-9-22]。造成的: [org.apache.camel.component.file.GenericFileOperationFailedException - 无法删除文件:GenericFile[C:\var\opt\irs\message\661.zip]] org.apache.camel.component.file.GenericFileOperationFailedException: 无法删除文件:GenericFile[C:\var\opt\irs\message\661.zip] at org.apache.camel.component.file.strategy.GenericFileDeleteProcessStrategy.commit(GenericFileDeleteProcessStrategy.java:89) 在 org.apache.camel.component.file.GenericFileOnCompletion.processStrategyCommit(GenericFileOnCompletion.java:127)

类似问题: Camel 2.15 file locks , Camel 2.14.2 not deleting files on Windows,deleting moving files

【问题讨论】:

  • Windows 中有一些其他进程对该文件进行了锁定,因此 Camel(例如 Java JVM)无法删除该文件。因此,请查看您的 Windows 框,什么可能会锁定文件。或者您在该直接路径(我们看不到)中执行某些操作,您忘记关闭某些文件输入或某事,因此文件被锁定。所以仔细检查你的代码。
  • 我只在文件组件上遇到这个问题。我尝试在 Windows 中使用 FTP,它工作正常。
  • 您在解压缩文件吗?无论如何打开 Zip 都会导致 zip 文件被锁定。

标签: apache-camel soa enterprise-integration


【解决方案1】:

在这种情况下,我忘了关闭文件输入流。所以这就是我在 Windows 中遇到问题的原因。

我对 Filecomponent 不必要地使用了 InputStream。我删除了它,一切正常的文件。

InputStream input = CamelContextHelper.convertTo(context, InputStream.class, body);

如果有人遇到同样的问题,只需正确关闭文件 InputStream 或交叉检查您的代码并尝试用其他适当的替代解决方案替换它。

替代解决方案:

如果您无法在代码中找到打开的流,则将以下参数应用于 Apache 骆驼路由。性能会更好。

readLockCheckInterval=1&amp;readLockTimeout=3

在我的情况下,Windows 中的性能要好得多。

【讨论】:

    猜你喜欢
    • 2021-01-04
    • 2018-01-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-07-19
    • 1970-01-01
    相关资源
    最近更新 更多