Random delay

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

Random delay

Anton-2
Hello

It seems the delay is fixed, when the route starts up.

How then, is it possible to have a random delay?

Thanks
Reply | Threaded
Open this post in threaded view
|

AW: Random delay

Jan Matèrne (jhm)
http://camel.apache.org/delayer.html lists at the end an example which delegates to a method computing the delay-time.

Jan

from("activemq:foo").
  delay().method("someBean", "computeDelay").
  to("activemq:bar");

public class SomeBean {
  public long computeDelay() {
     // use java code to compute a delay value in millis
     return new SecureRandom().nextLong();
  }
}



> -----Ursprüngliche Nachricht-----
> Von: Anton [mailto:[hidden email]]
> Gesendet: Samstag, 28. Mai 2016 11:34
> An: [hidden email]
> Betreff: Random delay
>
> Hello
>
> It seems the delay is fixed, when the route starts up.
>
> How then, is it possible to have a random delay?
>
> Thanks

Reply | Threaded
Open this post in threaded view
|

Re: Random delay

Anton-2
Thanks Jan

On Sat, May 28, 2016 at 11:56 AM, Jan Matèrne (jhm) <[hidden email]>
wrote:

> http://camel.apache.org/delayer.html lists at the end an example which
> delegates to a method computing the delay-time.
>

My apologies - I did not clearly describe what I am trying to achieve. I am
trying to achieve a different delay each time a message goes through the
route. Using the approach you desribed will create one delay time for each
message. Even if the method produces a random result, it is only called
when the route is created, so the same delay value is used for all messages.
Reply | Threaded
Open this post in threaded view
|

Re: Random delay

Claus Ibsen-2
On Sat, May 28, 2016 at 6:44 PM, Anton <[hidden email]> wrote:

> Thanks Jan
>
> On Sat, May 28, 2016 at 11:56 AM, Jan Matèrne (jhm) <[hidden email]>
> wrote:
>
>> http://camel.apache.org/delayer.html lists at the end an example which
>> delegates to a method computing the delay-time.
>>
>
> My apologies - I did not clearly describe what I am trying to achieve. I am
> trying to achieve a different delay each time a message goes through the
> route. Using the approach you desribed will create one delay time for each
> message. Even if the method produces a random result, it is only called
> when the route is created, so the same delay value is used for all messages.

The delay EIP will evaluate the expression and in this case its a method call.
And that method call is call a java bean method for each message.

Jan's sample code will calculate a random delay for each message (not once).



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