special delay

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

special delay

Joseph M'BIMBI-BENE
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:



Thank you


Reply | Threaded
Open this post in threaded view
|

Re: special delay

Claussnitzer, Ralf
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
>
>
Reply | Threaded
Open this post in threaded view
|

Re: special delay

Claus Ibsen-2
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
<[hidden email]> 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