Java 如果路由完成后移动文件失败,则让Apache Camel停止重试

Java 如果路由完成后移动文件失败,则让Apache Camel停止重试,java,file-io,exception-handling,locking,apache-camel,Java,File Io,Exception Handling,Locking,Apache Camel,下面的示例路由拾取一个文件并对其执行一系列操作。完成后,如camel:from字段中所述,将指示路由将文件移动到已处理的目录。或者,如果失败,将其移动到.error文件夹 当另一个进程作为文件的锁(即excel)和camel无法移动文件时,就会出现问题,因此,它会无限次地重试,这是一种不希望出现的行为 添加retrypolicy或onException不会解决此特定问题,因为我不想重试整个路由,而只想重试文件移动 <camel:route id="aRoute"> <c

下面的示例路由拾取一个文件并对其执行一系列操作。完成后,如
camel:from
字段中所述,将指示路由将文件移动到
已处理的
目录。或者,如果失败,将其移动到
.error
文件夹

当另一个进程作为文件的锁(即excel)和camel无法移动文件时,就会出现问题,因此,它会无限次地重试,这是一种不希望出现的行为

添加
retrypolicy
onException
不会解决此特定问题,因为我不想重试整个路由,而只想重试文件移动

<camel:route id="aRoute">
    <camel:from
            uri="file://{{sourceFileLocation}}?include=fileToProcess.csv&amp;moveFailed=.error/$simple{date:now:yyyy}/$simple{date:now:MM}/$simple{date:now:dd}/$simple{file:name}&amp;move=.processed/$simple{date:now:yyyy}/$simple{date:now:MM}/$simple{date:now:dd}/$simple{file:name}"/>
    <camel:setHeader headerName="CATEGORY">
        <camel:constant>category a</camel:constant>
    </camel:setHeader>
    <camel:process ref="asOfDateService"/>
    <camel:process ref="batchIdService"/>
    <camel:process ref="aService"/>
    <camel:to uri="log:aRoute"/>
    <camel:process ref="factXLookup"/>
    <camel:process ref="factXConversionInsert"/>
    <camel:process ref="batchTableCleanupService"/>
    <camel:process ref="batchUpdateService"/>
    <camel:onException>
        <camel:exception>java.lang.Exception</camel:exception>
        <camel:process ref="batchFailedService"/>
    </camel:onException>
</camel:route>

a类
java.lang.Exception
出于澄清目的,您可以忽略上面的
onException
,因为它处理的是流程的数据完整性/质量问题


TLDR:如何在完成后重试camel的文件移动,而不重新执行整个路由

这是文件组件需要处理的事情,而不是路由

您可以使用
readLock
选项(以及其他相关选项)配置文件组件如何处理锁定的文件。该选项在屏幕上有广泛的描述