camel-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Mike Spelling <mike_spell...@hotmail.com>
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 http://osdir.com/ml/users-camel-apache/2010-11/msg00134.html
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="http://www.springframework.org/schema/beans"

    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 

   xmlns:camel="http://camel.apache.org/schema/spring"

    xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd

        http://camel.apache.org/schema/spring http://camel.apache.org/schema/spring/camel-spring-2.0-M1.xsd">



    <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:delay> 

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

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

            </camel:delay> 

        </camel:route>



    </camel:camelContext>

</beans>
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!
Thanks,
Mike 		 	   		  
Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message