camel-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Mike Spelling <>
Subject Problems implementing a delay in a camel route
Date Tue, 24 Jan 2012 15:42:43 GMT

I'm using Camel v2.7.1 and trying to configure a route to apply a delay to incoming messages
before passing them on to another queue. I've read about a similar problem at
but the answer did not seem to work for me.
I don't think I can use  a <camel:constant> in the <camel:delay> block  as this
would block incoming messages, making new messages have to wait for any previous messages
to be routed before having another delay applied. The attribute asyncDelayed="true" in the
<camel:delay> block appeared to use a thread per message to ensure the correct delay
was applied which will quickly use up the maxConcurrentConsumers.
I therefore wanted to pass the delay block a custom method to calculate for correct delay
from the JMSHeader Timestamp.

My Camel configuration contains:
<?xml version="1.0" encoding="UTF-8"?>

<beans xmlns=""




    <bean id="RetryDelayCompute" class="myPackage.RetryDelayCompute" />

    <camel:camelContext autoStartup="true">

        <camel:endpoint id="endpoint-submit-in" uri="activemq:l2vc.pending?transacted=true"

        <camel:endpoint id="endpoint-submit-retrywait" uri="activemq:l2vc.retrywait" />

        <camel:route autoStartup="true" errorHandlerRef="pending.error"> 
            <camel:from ref="endpoint-submit-retrywait" />             <camel:log
message="Routing from retrywait queue..." />


               <camel:method ref="RetryDelayCompute" method="computeDelay"/>

                <camel:to ref="endpoint-submit-in" />               <camel:log message="Routing
to in queue..." /> 




My bean is below:

package myPackage;
@Componentpublic class RetryDelayCompute {			final static long TOTAL_DELAY_ON_QUEUE = 11000;
	public long computeDelay(@Header("JMSTimestamp") long jmsTimestamp) {		System.out.println("Calculating
delay...");		long now = System.currentTimeMillis();		long timeOnQueue = now - jmsTimestamp;
	return TOTAL_DELAY_ON_QUEUE - timeOnQueue;	}}
On running tests the method is never called. Although the component is instantiated the logs
show that the method never runs. Messages are simply routed to the correct queue with no delay.
Any help appreciated!
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message