You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@camel.apache.org by Joseph M'BIMBI-BENE <jo...@gmail.com> on 2020/02/26 20:09:40 UTC

special delay

Hello, i would like to know if that is possible in Camel to consumer with
an initial delay but not have a delay after every message. If that is not
clear, here is a picture of what is would like:

[image: image.png]

Thank you

Re: special delay

Posted by Claus Ibsen <cl...@gmail.com>.
Hi

Yeah it would be component specific if they have such a delay, for
example timer, quartz, scheduler etc has such thing.

But what you are asking for seems like to start routes delayed. At
this moment this is not supported generic. But as Ralf says you can
use a RoutePolicy and then manually start the route later. Or have
some thread that triggers after X time and start the routes you need
to start later.

What is your use case for such feature btw ?

On Thu, Feb 27, 2020 at 10:34 AM Ralf Claussnitzer
<ra...@slub-dresden.de> wrote:
>
> Hello Joseph,
>
> if the Consumer does not support the delay you can use a RoutePolicy to
> defer the actual route start:
>
> from("timer:hello")
>          .routeId("hello")
>          .routePolicy(new RoutePolicySupport() {
>                           @Override public void onInit(Route route) {
>                               super.onInit(route); final Runnable starter = () -> {
>                                   try {
>                                       final int millis =5000; log.info(String.format("Starting route %s after %d milliseconds", route.getId(), millis)); Thread.sleep(millis); startRoute(route); }catch (Exception e) {
>                                       handleException(e); }
>                               }; route.getRouteContext().getCamelContext()
>                                       .getExecutorServiceManager()
>                                       .newThread("DelayRouteStart", starter)
>                                       .start(); }
>                       }
>          )
>          .noAutoStartup()
>          .log("Hello from Timer");
>
> Notice that the route needs noAutoStartup().
>
> -Ralf
>
>
> On 2/26/20 9:09 PM, Joseph M'BIMBI-BENE wrote:
> > Hello, i would like to know if that is possible in Camel to consumer
> > with an initial delay but not have a delay after every message. If
> > that is not clear, here is a picture of what is would like:
> >
> > image.png
> >
> > Thank you
> >
> >



-- 
Claus Ibsen
-----------------
http://davsclaus.com @davsclaus
Camel in Action 2: https://www.manning.com/ibsen2

Re: special delay

Posted by Ralf Claussnitzer <ra...@slub-dresden.de>.
Hello Joseph,

if the Consumer does not support the delay you can use a RoutePolicy to 
defer the actual route start:

from("timer:hello")
         .routeId("hello")
         .routePolicy(new RoutePolicySupport() {
                          @Override public void onInit(Route route) {
                              super.onInit(route); final Runnable starter = () -> {
                                  try {
                                      final int millis =5000; log.info(String.format("Starting route %s after %d milliseconds", route.getId(), millis)); Thread.sleep(millis); startRoute(route); }catch (Exception e) {
                                      handleException(e); }
                              }; route.getRouteContext().getCamelContext()
                                      .getExecutorServiceManager()
                                      .newThread("DelayRouteStart", starter)
                                      .start(); }
                      }
         )
         .noAutoStartup()
         .log("Hello from Timer");

Notice that the route needs noAutoStartup().

-Ralf


On 2/26/20 9:09 PM, Joseph M'BIMBI-BENE wrote:
> Hello, i would like to know if that is possible in Camel to consumer 
> with an initial delay but not have a delay after every message. If 
> that is not clear, here is a picture of what is would like:
>
> image.png
>
> Thank you
>
>