1 Reply Latest reply on Jun 9, 2010 11:39 AM by clebert.suconic

    How to make a message sit on the queue for 10 seconds?

    swapnonil.mukherjee

      Hi All,

       

      We are using a Stateless Session Bean to post messages to a HornetQ JMS Queue. Our requirement is such that once messages are dropped on to the queue they must remain on the queue for a minimum of 10 seconds before being consumed by a Message Driven Bean.

       

      To achieve this functionality we tried to schedule the messages being dropped on to the queue like this.

       

      Queue queue = HornetQJMSClient.createQueue(queueName);
      MessageProducer producer = session.createProducer(queue);
      
      Message message = session.createObjectMessage(myObject);
      message.setLongProperty("_HQ_SCHED_DELIVERY", System.currentTimeMillis() + 10000);
      producer.send(queue, message);
      

       

      We have also placed a System.out.println on the first line inside the onMessage callback method of our Message Driven Bean. What we are seeing is that the onMessage method is being invoked immediately after a message is placed on the queue. In other words the message does not sit for 10 seconds on the queue. It is delivered immediately.

       

      Are we doing something wrong? Is scheduling the means to achieve the business functionality of a 10 second wait, or is there some other way by which this requirement can be meet?

        • 1. Re: How to make a message sit on the queue for 10 seconds?
          clebert.suconic

          I just tried here and it works.

           

          I'm not using the ResourceAdapter here though. Can you try a quick test using the regular ConnectionFactory (not java:/JmsXA) and see if it works.

           

          Also, I would use the constant defined just to be sure you don't have a typo in your code. I don't think that would be the cause of your failure.. but double check that one also:

           

          message.setLongProperty(org.hornetq.api.core.Message.HDR_SCHEDULED_DELIVERY_TIME.toString(), time);