【问题标题】:Getting Apache Camel to stop retrying if failed to move the file after route completion如果在路由完成后无法移动文件,则让 Apache Camel 停止重试
【发布时间】:2015-06-23 09:19:36
【问题描述】:

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

当另一个进程作为文件上的锁(即excel)并且camel无法移动文件时,就会出现问题,因此它会无限地不断重试,这是一种不受欢迎的行为。

添加retrypolicyonException 不会解决此特定问题,因为我不想重试整个路线而是仅重试文件移动

<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>

为澄清起见,您可以忽略上面的 onException,因为它处理的是数据完整性/流程质量方面的问题。

TLDR:如何在不重新执行整个路线的情况下重试骆驼的文件移动?

【问题讨论】:

    标签: java file-io exception-handling locking apache-camel


    【解决方案1】:

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

    您可以使用readLock 选项(以及其他相关选项)配置文件组件应如何处理锁定文件。该选项在 File2 component documentation page

    上有详细说明

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-07-01
      相关资源
      最近更新 更多