8 Replies Latest reply on Nov 6, 2005 10:33 PM by Alex Dorandish

    Artificially delaying messages

    Patrick Newbie


      We would like to delay queue messages by about 2-3 seconds so that our listner is only delivered the message after this "artificial delay". The external systems that provide messages that we in turn insert into a queue can not handle such a quick reply to a message.

      With out having to change our architecture from using a queue listener to creating a MessageConsumer that needs recreating for every message, does anyone know of a quick trick to delaying messages in a queue. A JBossMQ specific solution is also welcome.

      Using a selector does not solve the issue because the selection criteria changes with time.

      In sumary, is there a way to have a message inserted into a queue only delivered to the consumer after x number of seconds.


        • 1. Re: Artificially delaying messages
          Patrick Newbie

          Maybe a better way to view this questions is:

          Is there a way to schedule the delivery of a message? For example, can you insert a message in a queue and say, delivery to the consumer after 2 hours?

          I have searched around and I have not found any selector variable that can indicate the current time.

          I was thinking of a selector like:
          JMSTimestamp <currentTimeMillis - 60000

          where currentTimeMillis is a variable replaced by the current system time in miliseconds (i.e. like sysdate in Oracle). This selector would schedule delivery of every message to consumers one minute after the message has been inserted in the queue.

          Is there such a variable as currentTimeMillis? If not, I have to continually recreate the selector and update currentTimeMillis!

          • 3. Re: Artificially delaying messages
            Patrick Newbie

            I find no information regarding delaying messages in a queue in the FQA.

            From what I have studied, time-to-live regards how long the message will exist in the queue, not how long the message must stay in the queue.

            • 4. Re: Artificially delaying messages
              Patrick Newbie

              So I guess a JMS or JBossMQ wish list for the selector is a CURRENT_TIME variable...

              Safer to have a home made DB queue with a select that only pulls out messages that are older than x seconds.

              • 5. Re: Artificially delaying messages
                Ulf Schroeter Novice

                Use JBoss specific scheduled delivery

                aConnection = rQueueFactory.createQueueConnection(sQueueUser, sQueuePassword);
                aSession = aConnection.createQueueSession(false,QueueSession.AUTO_ACKNOWLEDGE);
                aSender = aSession.createSender(rQueue);
                TextMessage aMessage = aSession.createTextMessage();
                aMessage.setLongProperty("JMS_JBOSS_SCHEDULED_DELIVERY", aTransmissionNext.getTime());
                aSender.send( aMessage, DeliveryMode.PERSISTENT, ...);


                • 6. Re: Artificially delaying messages
                  Patrick Newbie

                  Thank you very much! Somehow missed it in the doc.

                  • 7. Re: Artificially delaying messages
                    Patrick Newbie

                    Actually, I looked for it in doc and did not find any mention of JMS_JBOSS_SCHEDULED_DELIVERY. I have only found reference to it in the SpyMessage JavaDoc (I could not guess to look there) and one topic in this forum plus some other odd places on the net.

                    I think that an amendment to the JBoss administration guide would be useful.

                    • 8. Re: Artificially delaying messages
                      Alex Dorandish Newbie

                      There is one thing I suggest you do after delaying.
                      Create a test class that sends messages every 2 hours and make sure you are not getting this error message:

                      org.jboss.mq.SpyJMSException: Exiting on IOE; - nested throwable: (java.io.EOFException)
                       at org.jboss.mq.Connection.asynchFailure(Connection.java:436)
                       at org.jboss.mq.il.uil2.UILClientILService.asynchFailure(UILClientILService.java:145)
                       at org.jboss.mq.il.uil2.SocketManager$ReadTask.handleStop(SocketManager.java:406)
                       at org.jboss.mq.il.uil2.SocketManager$ReadTask.run(SocketManager.java:338)
                       at java.lang.Thread.run(Thread.java:534)
                      Caused by: java.io.EOFException
                       at java.io.ObjectInputStream$BlockDataInputStream.readByte(ObjectInputStream.java:2603)
                       at java.io.ObjectInputStream.readByte(ObjectInputStream.java:845)
                       at org.jboss.mq.il.uil2.SocketManager$ReadTask.run(SocketManager.java:285)
                       ... 1 more

                      Jboss has awkward reactions to delayed messages.