Have you explored file:name option ?
You can add processor to the route which can set this option based on the
content size written to existing file so far. When limit is reached assign new
value to the camelFileName and reset the count to calculate content size in
processor.
For example:
Processor will have following logic:
public void process(Exchange exchange) throws Exception {
// you can also calculate total size written and then rotate
the file.
// For clarity i am changing fileName based on timestamp.
long number = System.currentTimeMillis() % 9 ;
String fileName = "File" + number + ".txt";
exchange.getIn().setHeader("camelFileName", fileName);
}
Route can look like this .....
<route>
<!-- read input from the console using the stream component -->
<from uri="timer:foo?period=1s"/>
<transform>
<simple>Message at ${date:now:yyyy-MM-dd
HH:mm:ss}</simple>
</transform>
<process ref="rotationProcessor"/>
<to uri="file://outdir?fileName=${file:name}"/>
</route>
Hope this helps.
-Ravi
________________________________________
From: mossro [[email protected]]
Sent: Monday, May 12, 2014 7:38 PM
To: [email protected]
Subject: File rotation
Hi,
I'm looking into using camel to support writing to file, the problem is that
these files will need to be rotated (new file after every x MB written).
I cannot obviously see anything on the File for dealing with this, and the
best i could think of is some how using <simple> with a choice to change the
to directory by using increment to change a suffix to a filename, but not
sure how i would even go about doing that.
Any help would be much appreciated.
Thanks,
Robin
--
View this message in context:
http://camel.465427.n5.nabble.com/File-rotation-tp5751026.html
Sent from the Camel - Users mailing list archive at Nabble.com.
This e-mail and any files transmitted with it are for the sole use of the
intended recipient(s) and may contain confidential and privileged information.
If you are not the intended recipient(s), please reply to the sender and
destroy all copies of the original message. Any unauthorized review, use,
disclosure, dissemination, forwarding, printing or copying of this email,
and/or any action taken in reliance on the contents of this e-mail is strictly
prohibited and may be unlawful.