4 Replies Latest reply on Jan 12, 2016 11:33 AM by vinod v

    Delayed Queue in Switchyard

    vinod v Newbie



      We are using switchyard for creating a number of web services.

      We have a requirement to send a message (xml) to a Queue with an initial delay of 5 hours.

      Another service consumes this Queue after 5 hours and processes the data  and if any validation failure , pushes the same Message into the same Queue with a different initial delay of 1 hour.

      The second service again consumes this  message after 1 hour and does the same validation and will re-queue the same message in case validation fails again with the same delay of 1 hour.

      We should be able to configure this delay.

      I was trying with JMS, but do not see a property like "initialDelay".

      I tried camelURI also, but the delay property is not seen.

      Any help will be appreciated.

      Do I need to use activeMQ or any other third party frameworks?


      The following is the code snippet from switchyard.xml


      <sca:reference name="AnotherService" multiplicity="0..1" promote="ServiceBean/AnotherService">

           <sca:interface.java interface="com.example.switchyard.filejms.AnotherService"/>

           <jms:binding.jms name="jms1">








        • 1. Re: Delayed Queue in Switchyard
          Jorge Morales Master


          I think JMS spec doesn't support for delayed messages, although some implementations does, like HornetQ and ActiveMQ, but depending on which JMS broker you are using details might be slightly different.


          Check this article:



          If you use HornetQ, just set a header for the message

          msg.setLongProperty(“JMS_JBOSS_SCHEDULED_DELIVERY”, now + delay);


          Hope it helps.

          Otherwise, read the specific broker documentation.

          Of course, you can do it in various alternative ways, using quartz endpoint to trigger consumption.



          • 2. Re: Delayed Queue in Switchyard
            vinod v Newbie

            Hi Jorge,


            Thanks a lot for the reply.

            We are using switchyard and sets the properties through switchyard diagram.

            I tried to set the property "JMS_JBOSS_SCHEDULED_DELIVERY” through switchyard for "JMS", but the system doesn't recognize the property.


            Hence I tried the following way.I am not using JMS anymore.



                   .log("Received message for 'MyOwnCamelRoute' : ${body}")





            This is working properly.

            The delay happens correct, but the call is not asynchronous.

            Even though I set the "asyncDelayed, the control comes back only after the delay.


            Am I doing anything wrong here?What steps needs to be done for making this an asynchronous call?




            • 3. Re: Delayed Queue in Switchyard
              Jorge Morales Master

              Hi Anand,

              Since I'm not a Camel expert, I can not be of any help here.

              Have you tried the pattern in Camel standalone in a JUnit? This is to sort if there is a problem with the route, or with SwitchYard implementation. Then, depending on the source of the problem, if it is Camel related, I recommend you asking in the camel community, or camel irc as there is a very active community of camel practitioners out there.



              • 4. Re: Delayed Queue in Switchyard
                vinod v Newbie



                Found a solution to this.

                I am adding this here if it can be helpful for others.

                Added a contextMapper class in switchyard something like this.

                public class MyMapper extends org.switchyard.component.camel.common.composer.CamelContextMapper{


                import org.apache.camel.Exchange;

                import org.apache.camel.Message;

                import org.switchyard.Context;

                import org.switchyard.component.camel.common.composer.CamelBindingData;


                public class MyMapper extends org.switchyard.component.camel.common.composer.CamelContextMapper{



                     public void mapTo(Context context, CamelBindingData target) throws Exception{


                           Message message = target.getMessage();       

                           super.mapTo(context, target);

                           long time = System.currentTimeMillis();

                           time += 20000;//add the time delay here

                           message.setHeader("_HQ_SCHED_DELIVERY", time);