失败时骆驼移动文件

Camel move file on failure

我正在尝试编写一个路径来扫描 'input' 目录,如果找到 .gz 文件,将内容提取到二级目录,如果发生错误(例如损坏的 .gz),它将移动文件到错误目录

实际发生的是文件开始正确写出内容,然后出现错误-GZLIB异常,原件正确放入错误目录但'input'中的.gz不是因异常被删除

因此路由将不断打开,开始提取然后使文件失败并一直重复下去。我需要它在失败时从 'input' 目录中删除文件,这样它就不会被重新处理。我希望 .to( ) 到一个文件位置来实现这一点,因为它通常表现为移动。

onException( Exception.class )
     .to( "file://error_directory" )
.end()

from( "file://input" )
.choice()
    .when( {filename matches *.gz} )
        {unzip Gzip contents}
        .to( "file://output" )
    .when( ) ... 
.end()

您可以直接在文件使用者的文件端点上使用 moveFailed 选项,而不是 onException。然后,如果有异常,原始文件将被移动。

所以像

from( "file://input?moveFailed=error_directory" )
.choice()
    .when( {filename matches *.gz} )
        {unzip Gzip contents}
        .to( "file://output" )
    .when( ) ... 
.end()

您可以在 Camel 文档中阅读有关 moveFailed 的更多信息:http://camel.apache.org/file2