one way to do this is to use the http://camel.apache.org/aggregator2.html aggregator 's completionFromBatchConsumer mode. This will allow you to group exchanges together based on the size of the file batch, etc...
from("file:inbound?maxMessagesPerPoll=20") .process(...) .aggregator(constant(true), MyAggregationStrategy()).completionFromBatchConsumer() .to("log:finishedBatch"); OrackBahama wrote: > > Hi, > > although I've read several posts for this, I'm quite unsure if the > "onCompletion" construct will fit my needs. > As far as I've understood, this is a hook that's called after completion > of the route (when defined in front of the "from" ...). > > I'll explain my problem in the following example. > I want to process the files in a directory and every file should result in > one log entry - successful or not. > Then, after all files have been processed, the logfile should be closed > and transferred back to the customer. > > Assume, we have 100 files -> then the logfile contains 100 lines. > Question: If I restrict the messages per poll (let's say twenty) - will > that result in 5 calls of "onCompletion" (and 5 logfiles with 20 lines) ? > Is that meant with "UnitOfWork" ? > > public class CompletionTestRouteBuilder extends RouteBuilder > { > > /***************************************************************************** > * > * @throws Exception > > ****************************************************************************/ > @Override > public void configure() throws Exception > { > onCompletion() > // close whole logfile and transfer it to customer > // contains one line per processed file > // purpose: one logfile per directory poll/UnitOfWork > ... > ; > > from( "file:C:/tmp/inbox" // + "?maxMessagesPerPoll=20" > ) > > // process file and write log entry per-file in logfile > ... > .to( "file:C:/tmp/outbox" ) > ; > } > } > > > Hopefully someone could explain a bit - thanks in advance ! > > Best regards > ----- Ben O'Day IT Consultant -http://consulting-notes.com -- View this message in context: http://camel.465427.n5.nabble.com/Global-onCompletion-tp4794456p4795874.html Sent from the Camel - Users mailing list archive at Nabble.com.