Reputation: 451
I am working on replacing data in file (it's big file of 400 MB) using camel and I am facing issue where other consumer pickup file even though file is in use (it's in writing mode).
Is there a way in Camel to lock file which is in writing mode so another consumer/route can't consume. It should consume once the writing is done. I tried with readLocks but no luck so far.
from("file://A").split().tokenize("\n", 999).streaming()
.log("Spliting::::::::::").unmarshal(csv).bean("transferDate", "enrich")
.marshal(csv).to("file://B?fileExist=Append");
from("file://B?delete=true").to("file://A"); // this route pick up file even the first route haven't finished writing file completely
Upvotes: 1
Views: 433
Reputation: 56
You should configure the Camel route with appropriate options for file reading and writing. In particular, you need to set the readLock and readLockTimeout options for the file endpoint.
from("file:/input-directory")
.routeId("fileRoute")
.to("file:/output-directory?readLock=changed&readLockTimeout=5000")
.log("File processed: ${file:name}")
.end();
Upvotes: 2
Reputation: 7005
You can use done files. If you configure them on the file consumer, it ignores all files until there is a done (or marker) file beside the real file.
You can also configure the file producer to create the done files.
See the Camel Docs for File component and go done to the chapter Using done files
.
Upvotes: 1