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!
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.
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.
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, ...);
Thank you very much! Somehow missed it in the doc.
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.
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.