如果在路由完成后移动文件失败,让 Apache Camel 停止重试
Getting Apache Camel to stop retrying if failed to move the file after route completion
下面的示例路由选择一个文件并对它们执行一系列操作。完成后,如 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
上有详尽的描述
下面的示例路由选择一个文件并对它们执行一系列操作。完成后,如 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