You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@camel.apache.org by OrackBahama <jd...@metadok.de> on 2011/09/12 16:45:43 UTC
Global onCompletion
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
--
View this message in context: http://camel.465427.n5.nabble.com/Global-onCompletion-tp4794456p4794456.html
Sent from the Camel - Users mailing list archive at Nabble.com.
Re: Global onCompletion
Posted by boday <be...@initekconsulting.com>.
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.
Re: Global onCompletion
Posted by Donald Whytock <dw...@gmail.com>.
I believe OnCompletion is called on each exchange. One file should be
one exchange, so each file would generate a call to OnCompletion.
If polling is restricted to 20 files at a time, that should still be
20 exchanges, resulting in 20 calls to OnCompletion.
Don
On Mon, Sep 12, 2011 at 10:45 AM, OrackBahama <jd...@metadok.de> 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
>
> --
> View this message in context: http://camel.465427.n5.nabble.com/Global-onCompletion-tp4794456p4794456.html
> Sent from the Camel - Users mailing list archive at Nabble.com.
>