简体   繁体   中英

Getting Apache Camel to stop retrying if failed to move the file after route completion

The example route below picks up a file and performs a series of operations on them. Once completed, as noted in the camel:from field, the route is instructed to move the file to a .processed directory. Alternatively if failed, move it to the .error folder.

The problem occurs when another process as a lock on the file (ie. excel) and camel is unable to move the file, therefore, it infinitely keeps retrying which is an undesired behaviour.

Adding a retrypolicy or onException will not solver this specific issue as I would not like to retry the entire route but rather retry the file move only

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

For clarification purposes you can ignore the onException above as that is dealing with issues in the data integrity / quality of the process.

TLDR : How can I retry camel's file-move on completion without re-executing the entire route?

This is something that the File component needs to handle, not your route.

You can configure how the File component should handle locked files using the readLock option (along with other related options). The option has an extensive description on the File2 component documentation page

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM