You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@camel.apache.org by cristisor <cr...@yahoo.com> on 2013/06/21 12:59:49 UTC
Mixing ChoiceDefinition with DelayDefinition
Hello,
I have the following route:
from(startEndpoint)
.choice()
.when(fileIsComplete()).delay(COMPLETION_TIMEOUT).process(processor).to(outputEndpoint)
.otherwise().aggregate(new ObjectsAggregator()).constant(true)
.completionSize(BATCH_SIZE).completionTimeout(COMPLETION_TIMEOUT)
.process(processor).stop();
So, if the fileIsComplete is true, process only one exchange and send the
response to another endpoint otherwise aggregate up to a number of
BATCH_SIZE, process in the end, and stop the routing.
Because my Camel version is pretty old (2.4.0-fuse-00-00) I don't have
"endChoice", so if I insert the delay or the aggregator I can't access the
"otherwise" branch. I really need both of them so I thought to insert
another processor, before the actual processing, that puts the current
thread to sleep for COMPLETION_TIMEOUT and leave the aggregation to the
other branch, since I won't have to continue using the ChoiceDefinition.
Is there a better way to solve this problem without upgrading the Camel
version?
Thanks.
--
View this message in context: http://camel.465427.n5.nabble.com/Mixing-ChoiceDefinition-with-DelayDefinition-tp5734524.html
Sent from the Camel - Users mailing list archive at Nabble.com.
Re: Mixing ChoiceDefinition with DelayDefinition
Posted by cristisor <cr...@yahoo.com>.
Thanks for your quick answer. Now I only have to adjust the delay.
--
View this message in context: http://camel.465427.n5.nabble.com/Mixing-ChoiceDefinition-with-DelayDefinition-tp5734524p5734536.html
Sent from the Camel - Users mailing list archive at Nabble.com.
Re: Mixing ChoiceDefinition with DelayDefinition
Posted by cristisor <cr...@yahoo.com>.
Hello Claus,
I have one more question. This is the working route, as per your advice:
from(startEndpoint)
.choice()
.when(fileIsNotComplete())
.to(tempEndpoint)
.otherwise()
.delay(5 * COMPLETION_TIMEOUT)
.process(processor).to(outputEndpoint);
from(tempEndpoint)
.aggregate(new ObjectsAggregator()).constant(true)
.completionSize(BATCH_SIZE).completionTimeout(COMPLETION_TIMEOUT)
.process(processor).stop();
My purpose is to process all the exchanges that come from a file, through a
couple of routes that do extra processing, but allow only for the last
exchange, which is detected inside "fileIsNotComplete", to go to a final
endpoint and set a "file done" flag into the database, so that the first
route of the business logic can start processing another file.
Even though the process method is synchronized and I inserted the big delay,
there are situations when the final exchange, the one going to the "when()"
choice, gets its turn to be processed before other batches of exchanges,
from the "otherwise" choice, which are waiting in line.
Is there a way to pause/forbid route "when" to do its job until route
"otherwise" will have finished everything?
Thanks.
--
View this message in context: http://camel.465427.n5.nabble.com/Mixing-ChoiceDefinition-with-DelayDefinition-tp5734524p5734708.html
Sent from the Camel - Users mailing list archive at Nabble.com.
Re: Mixing ChoiceDefinition with DelayDefinition
Posted by Claus Ibsen <cl...@gmail.com>.
Hi
Use a new route for the aggregate, and then use "direct:xxx" endpoint
from the choice to call that route.
On Fri, Jun 21, 2013 at 12:59 PM, cristisor <cr...@yahoo.com> wrote:
> Hello,
>
> I have the following route:
> from(startEndpoint)
> .choice()
> .when(fileIsComplete()).delay(COMPLETION_TIMEOUT).process(processor).to(outputEndpoint)
> .otherwise().aggregate(new ObjectsAggregator()).constant(true)
> .completionSize(BATCH_SIZE).completionTimeout(COMPLETION_TIMEOUT)
> .process(processor).stop();
>
> So, if the fileIsComplete is true, process only one exchange and send the
> response to another endpoint otherwise aggregate up to a number of
> BATCH_SIZE, process in the end, and stop the routing.
>
> Because my Camel version is pretty old (2.4.0-fuse-00-00) I don't have
> "endChoice", so if I insert the delay or the aggregator I can't access the
> "otherwise" branch. I really need both of them so I thought to insert
> another processor, before the actual processing, that puts the current
> thread to sleep for COMPLETION_TIMEOUT and leave the aggregation to the
> other branch, since I won't have to continue using the ChoiceDefinition.
>
> Is there a better way to solve this problem without upgrading the Camel
> version?
>
> Thanks.
>
>
>
> --
> View this message in context: http://camel.465427.n5.nabble.com/Mixing-ChoiceDefinition-with-DelayDefinition-tp5734524.html
> Sent from the Camel - Users mailing list archive at Nabble.com.
--
Claus Ibsen
-----------------
www.camelone.org: The open source integration conference.
Red Hat, Inc.
FuseSource is now part of Red Hat
Email: cibsen@redhat.com
Web: http://fusesource.com
Twitter: davsclaus
Blog: http://davsclaus.com
Author of Camel in Action: http://www.manning.com/ibsen