You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@camel.apache.org by Anton <ku...@gmail.com> on 2016/05/28 09:34:10 UTC

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

Re: Random delay

Posted by Claus Ibsen <cl...@gmail.com>.
On Sat, May 28, 2016 at 6:44 PM, Anton <ku...@gmail.com> wrote:
> Thanks Jan
>
> On Sat, May 28, 2016 at 11:56 AM, Jan Matèrne (jhm) <ap...@materne.de>
> 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

Re: Random delay

Posted by Anton <ku...@gmail.com>.
Thanks Jan

On Sat, May 28, 2016 at 11:56 AM, Jan Matèrne (jhm) <ap...@materne.de>
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.

AW: Random delay

Posted by "Jan Matèrne (jhm)" <ap...@materne.de>.
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:kurrent93@gmail.com]
> Gesendet: Samstag, 28. Mai 2016 11:34
> An: users@camel.apache.org
> 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