0

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
bvyas
  • 384
  • 3
  • 10
  • do you have a specific business case you need fileExist=Append in your first route and deleting it in the second route. I would suggest in first route fileExist=Override and use tempFileName=tmpFile_${file:name} so that a temp file is being written to. Or you can use use doneFileName option in first route and in the second route pick the file when the doneFileName exists. – Neeraj May 10 '18 at 17:26
  • @Neeraj : I need fileExist=Append due to I am writing data in chucks of 999 and I am doing this because it's a very big file. I tried with tempFileName but it didn't work as Camel won't allow ( fileExist and tempFileName) to use both option at a time – bvyas May 10 '18 at 18:35
  • This question's requirement is pretty close to [this](https://stackoverflow.com/q/49762430/3759505) – hk6279 May 11 '18 at 02:33

1 Answers1

1

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.

burki
  • 6,741
  • 1
  • 15
  • 31