首页 > 解决方案 > Apache-Camel 文件递归移动到同一子目录

问题描述

我目前有一条骆驼路线,它处理一个 zip 文件,然后将其移动到一个存储文件夹。

from(
    file://importDir?recursive=true&preMove=processing&move=storage&moveFailed=error&include=.*\\.zip$
).bean(bean, "process")

在实际导入中,-Directory 是带有 zip 文件的子目录。我想在storage目录中也有相同的子目录,也可能在processing目录中。知道我是否可以使用路由和文件语言表达式来做到这一点?

标签: apache-camel

解决方案


由于您已设置recursive=true,因此无法设置move=storage,因为这会导致循环。

例如:

  1. file.zip 被放置到/importDir/some-folder/
  2. 文件使用者读取文件并将其发送给处理器
  3. 处理后将原始文件存储到/importDir/some-folder/storage/
  4. 文件使用者递归地从/importDir/some-folder/storage/
  5. 处理后的地方再放/importDir/some-folder/storage/storage/
  6. 无限重复

现在您可以做的是设置move=.storage将文件放置在上面的示例中/importDir/some-folder/.storage/,文件使用者端点将忽略该文件。

/importDir/更清洁的解决方案是使用例如将处理后的文件存储在外部move=/somepath/storage/${file:name}骆驼文档中有关此的更多信息

使用 ${file:name},目录结构在 storage 和 importDir 中应该保持不变。


推荐阅读