DelayerThe Delayer Pattern allows you to delay the delivery of messages to some destination.
Options
Using the Fluent Builders from("seda:b").delay(1000).to("mock:result"); So the above example will delay all messages received on seda:b 1 second before sending them to mock:result. You can of course use many different Expression languages such as XPath, XQuery, SQL or various Scripting Languages. You can just delay things a fixed amount of time from the point at which the delayer receives the message. For example to delay things 2 seconds delayer(2000) The above assume that the delivery order is maintained and that the messages are delivered in delay order. If you want to reorder the messages based on delivery time, you can use the Resequencer with this pattern. For example from("activemq:someQueue").resequencer(header("MyDeliveryTime")).delay("MyRedeliveryTime").to("activemq:aDelayedQueue"); Spring DSLThe sample below demonstrates the delay in Spring DSL: <bean id="myDelayBean" class="org.apache.camel.processor.MyDelayCalcBean"/> <camelContext xmlns="http://camel.apache.org/schema/spring"> <route> <from uri="seda:a"/> <delay> <header>MyDelay</header> </delay> <to uri="mock:result"/> </route> <route> <from uri="seda:b"/> <delay> <constant>1000</constant> </delay> <to uri="mock:result"/> </route> <route> <from uri="seda:c"/> <delay> <method ref="myDelayBean" method="delayMe"/> </delay> <to uri="mock:result"/> </route> </camelContext> For further examples of this pattern in use you could look at the junit test case Asynchronous delayingAvailable as of Camel 2.4 You can let the Delayer use non blocking asynchronous delaying, which means Camel will use a scheduler to schedule a task to be executed in the future. The task will then continue routing. This allows the caller thread to not block and be able to service other messages etc. From Java DSLYou use the asyncDelayed() to enable the async behavior. from("activemq:queue:foo").delay(1000).asyncDelayed().to("activemq:aDelayedQueue"); From Spring XMLYou use the asyncDelayed="true" attribute to enable the async behavior. <route> <from uri="activemq:queue:foo"/> <delay asyncDelayed="true"> <constant>1000</constant> </delay> <to uri="activemq:aDealyedQueue"/> </route> Creating a custom delayYou can use an expression to determine when to send a message using something like this from("activemq:foo"). delay().method("someBean", "computeDelay"). to("activemq:bar"); then the bean would look like this... public class SomeBean { public long computeDelay() { long delay = 0; // use java code to compute a delay value in millis return delay; } } Using This PatternIf you would like to use this EIP Pattern then please read the Getting Started, you may also find the Architecture useful particularly the description of Endpoint and URIs. Then you could try out some of the Examples first before trying this pattern out. See Also |