BTW I think that if you use delayer(3000) and set concurentConsumers=1
on JMS endpoint it will work the way you want as delayer simply calls
Thread.sleep() as far as I remember.

Then every mesasge will be delayed for 3 sec and the second message
will wait for the previous one to complete.

Roman

2008/5/12 James Strachan <[EMAIL PROTECTED]>:
> Awesome! Phew! Thanks for letting us know :)
>
>
>
>  2008/5/12 Krystian Szczesny <[EMAIL PROTECTED]>:
>  >
>  >
>  >
>  >
>  >  James.Strachan wrote:
>  >  >
>  >  > 2008/5/12 Krystian Szczesny <[EMAIL PROTECTED]>:
>  >  >>  James.Strachan wrote:
>  >  >>  >
>  >  >>  > 2008/5/9 Krystian Szczesny <[EMAIL PROTECTED]>:
>  >  >>  >>
>  >  >>  >>
>  >  >>  >>
>  >  >>  >> James.Strachan wrote:
>  >  >>  >>>
>  >  >>  >>> 2008/5/9 Krystian Szczesny <[EMAIL PROTECTED]>:
>  >  >>  >>>>
>  >  >>  >>>>  Hi,
>  >  >>  >>>>
>  >  >>  >>>>
>  >  >>  >>>>  Before, when delaying single messages I've used for example
>  >  >>  >>>> delayer(3000)
>  >  >>  >>>>  and it worked flawlessly.
>  >  >>  >>>>  Now I need to delay a sequence of messages, so when I send 5
>  >  >> messages,
>  >  >>  >>>> the
>  >  >>  >>>>  first should be delayed by 3000, second by 6000 etc...
>  >  >>  >>>>
>  >  >>  >>>>  Is there any way I could do that with Camel?
>  >  >>  >>>
>  >  >>  >>> You just need to use an expression for the time that the message 
> is
>  >  >> to
>  >  >>  >>> be sent at. So you could do something like...
>  >  >>  >>>
>  >  >>  >>> from("activemq:foo").delay().method("someBean",
>  >  >>  >>> "sendAtTime").to("activemq:bar");
>  >  >>  >>>
>  >  >>  >>> then the bean would look like this...
>  >  >>  >>>
>  >  >>  >>> public class SomeBean {
>  >  >>  >>>   public long sendAtTime(@Header("MyDelayHeader") long delay) {
>  >  >>  >>>     if (delay <= 0) delay = 3000;
>  >  >>  >>>     return System.currentTimeMillis() + delay;
>  >  >>  >>>  }
>  >  >>  >>> }
>  >  >>  >>>
>  >  >>  >>> which would look for the MyDelayHeader on the message and use that
>  >  >> as
>  >  >>  >>> the
>  >  >>  >>> delay.
>  >  >>  >>>
>  >  >>  >>>
>  >  >>  >>> --
>  >  >>  >>> James
>  >  >>  >>> -------
>  >  >>  >>> http://macstrac.blogspot.com/
>  >  >>  >>>
>  >  >>  >>> Open Source Integration
>  >  >>  >>> http://open.iona.com
>  >  >>  >>>
>  >  >>  >>>
>  >  >>  >> Hi James,
>  >  >>  >>
>  >  >>  >> thanks for fast answer.
>  >  >>  >> One more thing if you could...
>  >  >>  >> I am using spring to configure the whole thing:
>  >  >>  >>
>  >  >>  >>        <camelContext id="camel"
>  >  >>  >>
>  >  >> xmlns="http://activemq.apache.org/camel/schema/spring";>
>  >  >>  >>                <route>
>  >  >>  >>                        <from uri="activemq:queue:Input" />
>  >  >>  >>                        <delayer>
>  >  >>  >>                                <simple>header.JMSTimestamp</simple>
>  >  >>  >>                                <to uri="activemq:queue:Delayed" />
>  >  >>  >>                                <delay>3000</delay>
>  >  >>  >>                        </delayer>
>  >  >>  >>                </route>
>  >  >>  >>        </camelContext>
>  >  >>  >>
>  >  >>  >> How can I add "method("someBean","sendAtTime")" to this
>  >  >> configuration?
>  >  >>  >
>  >  >>  > <delayer>
>  >  >>  >   <methodCall bean="something" method="sendAtTime"/>
>  >  >>  >   ...
>  >  >>  > </delayer>
>  >  >>  >
>  >  >>  > For more details, configure your IDE to use the XSD...
>  >  >>  > 
> http://activemq.apache.org/camel/schema/spring/camel-spring-1.3.0.xsd
>  >  >>  >
>  >  >>  > then you'll get smart completion
>  >  >>  >
>  >  >>  > --
>  >  >>  > James
>  >  >>  > -------
>  >  >>  > http://macstrac.blogspot.com/
>  >  >>  >
>  >  >>  > Open Source Integration
>  >  >>  > http://open.iona.com
>  >  >>  >
>  >  >>  >
>  >  >>
>  >  >>  Thx James,
>  >  >>
>  >  >>  I've configured Eclipse to use the xsd file, but it does not support
>  >  >> smart
>  >  >>  completion i guess, it shows everything there is. But never mind that.
>  >  >
>  >  > Strange - works for me in IntellIJ though :)
>  >  >
>  >  >>
>  >  >>  I've tried couple of scenarios [delay method returns
>  >  >>  System.currentTimeMillis() + 5000]:
>  >  >>
>  >  >>  FIRST
>  >  >>         <camel:camelContext id="camel">
>  >  >>                 <camel:route>
>  >  >>                         <camel:from uri="activemq:queue:Delayed" />
>  >  >>                         <camel:delayer>
>  >  >>                                         <camel:methodCall
>  >  >> bean="delayerBean" method="delay"/>
>  >  >>                                         <camel:to
>  >  >> uri="activemq:queue:Output" />
>  >  >>                         </camel:delayer>
>  >  >>                 </camel:route>
>  >  >>         </camel:camelContext>
>  >  >>
>  >  >>  Message is delivered to consumer of Output queue before the delay 
> method
>  >  >> is
>  >  >>  being called.
>  >  >>
>  >  >>  SECOND:
>  >  >>         <camel:camelContext id="camel">
>  >  >>                 <camel:route>
>  >  >>                         <camel:from uri="activemq:queue:Delayed" />
>  >  >>                         <camel:delayer>
>  >  >>                                         <camel:methodCall
>  >  >> bean="delayerBean" method="delay"/>
>  >  >>                         </camel:delayer>
>  >  >>                         <camel:to uri="activemq:queue:Output" />
>  >  >>                 </camel:route>
>  >  >>         </camel:camelContext>
>  >  >>  Result: same as above - message is consumed before the delay method is
>  >  >>  called.
>  >  >>
>  >  >>  Then I've tried with a class:
>  >  >>  public class CamelRoute extends RouteBuilder {
>  >  >>
>  >  >>           @Override
>  >  >>           public void configure() throws Exception {
>  >  >>
>  >  >> from("activemq:queue:Delayed").delayer().method("delayerBean",
>  >  >>  "delay").to("activemq:queue:Output");
>  >  >>           }
>  >  >>  }
>  >  >>
>  >  >>  and still same result. Message is sent to Output without any delay :/
>  >  >>
>  >  >>  What am I doing wrong?
>  >  >
>  >  > Your code looks valid to me; I guess there's some kinda bug in there
>  >  > somewhere. Will try take a look soon (I'm in the middle of a big
>  >  > refactor...)
>  >  >
>  >  > --
>  >  > James
>  >  > -------
>  >  > http://macstrac.blogspot.com/
>  >  >
>  >  > Open Source Integration
>  >  > http://open.iona.com
>  >  >
>  >  >
>  >
>  >
>  >  James... sorry about that.
>  >  I've spotted the bug just before you've replied.
>  >  I've added a new queue to my configuration and forgot to change the 
> message
>  >  listener configuration... so onMessage was hitting on wrong queue :/
>  >
>  >  Sorry again for that, it works like a charm now.
>  >  --
>  >  View this message in context: 
> http://www.nabble.com/Delay-messages-with-camel-sequentially-tp17144701s22882p17186941.html
>  >
>  >
>  > Sent from the Camel - Users mailing list archive at Nabble.com.
>  >
>  >
>
>
>
>  --
>
>
> James
>  -------
>  http://macstrac.blogspot.com/
>
>  Open Source Integration
>  http://open.iona.com
>

Reply via email to