File componenter og om store filer ikke indlæses når den kopieres ind i en folder

8 views
Skip to first unread message

aag...@gmail.com

unread,
Jul 5, 2011, 4:26:01 PM7/5/11
to Camel User Group-Denmark
På vej hjem i bilen snakkede vi om det med at kopiere en stor fil ind
på en server som Camel overvåger - venter Camel på at filen er skrevet
færdig ?

Dokumentationen siger:

Avoid reading files currently being written by another application
Beware the JDK File IO API is a bit limited in detecting whether
another application is currently writing/copying a file. And the
implementation can be different depending on OS platform as well. This
could lead to that Camel thinks the file is not locked by another
process and start consuming it. Therefore you have to do you own
investigation what suites your environment. To help with this Camel
provides different readLock options and doneFileOption option that you
can use. See also the section Consuming files from folders where
others drop files directly.

tak for et godt pre-møde ;-)

/aage

Søren Markert

unread,
Jul 6, 2011, 4:22:06 AM7/6/11
to Camel User Group-Denmark
Jamen så er det jo med at teste det selv for det/de OS, man bruger.

aag...@gmail.com

unread,
Jul 6, 2011, 4:24:11 AM7/6/11
to Camel User Group-Denmark
Tjek - jeg test mac ;-)

/aage

aag...@gmail.com

unread,
Jul 6, 2011, 10:08:58 AM7/6/11
to Camel User Group-Denmark
Hmmm det virker ikke out-of-the-box på en mac. Hvis jeg kopiere en fil
på 53mb til ind folderen, så bliver ca. halvdelen (eller mindre)
kopieret til out. Jeg kan dog se at filen låses af Camel, når den
begynder at kopiere og at den "husker" filen hvis jeg kopiere den
samme ind igen.

CamelContext context = new DefaultCamelContext();
try {
context.addRoutes(new RouteBuilder() {
public void configure() {
from("file:/Users/ani/camel-in").to("file:/Users/ani/camel-
out");
from("file:/Users/ani/camel-out").process(new Processor()
{
public void process(Exchange e) {
System.out.println("Fil " + e.getIn()+" er
kopieret");
}
});
}
});
context.start();
} catch (Exception e) {
e.printStackTrace();
}

Det må kunne løses ;-) på en eller anden snedig måde (læs: parameter).

/aage

René Vangsgaard

unread,
Jul 6, 2011, 10:16:08 AM7/6/11
to camel-user-g...@googlegroups.com
Fra afsnittet "Consuming files from folders where others drop files directly" på http://camel.apache.org/file2.html
Beware if you consume files from a folder where other applications write files directly. Take a look at the different readLock options to see what suits your use cases. The best approach is however to write to another folder and after the write move the file in the drop folder. However if you write files directly to the drop folder then the option changed could better detect whether a file is currently being written/copied as it uses a file changed algorithm to see whether the file size / modification changes over a period of time. The other read lock options rely on Java File API that sadly is not always very good at detecting this. You may also want to look at the doneFileName option, which uses a marker file (done) to signal when a file is done and ready to be consumed.
Hvilket minder om det trick vi plejer at bruge når vi "consumer" filer fra en FTP-folder, pre-Camel.

davsclaus

unread,
Jul 6, 2011, 12:27:35 PM7/6/11
to Camel User Group-Denmark
Den default read lock strategy i Camel er den fra Camel 1.x (saa den
er lidt gammel).
Den skriver en .camelLock fil hvis der ikke findes en saadan fil i
forvejen.

Derfor er der bedre read lock strategier som er dokumentere her
http://camel.apache.org/file2

F.eks. fra JDK er der et FileLock API, men den er typisk JVM-wide or
kan være forskellig fra JDK/OS til JDK/OS.
Du kan bruge denne locking strategi i Camel med readLock=fileLock

Så selvom du maaske laver readLock=fileLock og laver en unit test som
hvor baade producer + consumer
koerer i samme JVM saa kan det alligevel betyde a FileLock APIet ikke
locker filen.

Der er dog en anden lock strategy som typisk er lidt bedre, i det du
kan bruge fileLock=rename.
Dvs Camel forsoger at rename filen inden den laeser den. Det er en IO
operation og typisk paa et OS
kan man ikke rename en file som er ved at blive written

Og vi har ogsaa en changed, som kikker paa om filen aendre sig over
tid etc.

Ja det er lidt som i gamle dage med FTP filer (evt dengang man havde
DONE files) osv.

PS: Jeg skriver typisk engelsk hver dag saa jeg har ikke et dansk
tastatur.

Happy riding on the Camel

--
Claus Ibsen
-----------------
FuseSource
Email: cib...@fusesource.com
Web: http://fusesource.com
Twitter: davsclaus, fusenews
Blog: http://davsclaus.blogspot.com/
Author of Camel in Action: http://www.manning.com/ibsen/
Reply all
Reply to author
Forward
0 new messages