下面的示例路由选取一个文件并对它们执行一系列操作。完成后,如 camel:from
字段中所述,将指示路由将文件移动到 .processed
目录。或者,如果失败,请将其移至 .error
文件夹。
当另一个进程作为文件上的锁(即 Excel)并且 Camel 无法移动文件时,就会出现问题,因此,它会无限地不断重试,这是一种不希望的行为。
添加 retrypolicy
或 onException
不会解决此特定问题,因为我不想重试整个路由而是重试文件只移动
<camel:route id="aRoute">
<camel:from
uri="file://{{sourceFileLocation}}?include=fileToProcess.csv&moveFailed=.error/$simple{date:now:yyyy}/$simple{date:now:MM}/$simple{date:now:dd}/$simple{file:name}&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>
为了澄清起见,您可以忽略上面的onException
,因为它正在处理流程的数据完整性/质量问题。
TLDR:如何在完成后重试camel的文件移动而不重新执行整个路线?
最佳答案
这是文件组件需要处理的事情,而不是您的路线。
您可以使用 readLock
选项(以及其他相关选项)配置文件组件应如何处理锁定的文件。该选项在 File2 component documentation page 上有详细描述。
关于java - 如果在路由完成后未能移动文件,让 Apache Camel 停止重试,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30998764/