Delayed Message Queue Best Practice
jms
Solution
JMS 2.0 supports message delaying; see the spec, section 7.9: You can call `setDeliveryDelay` on the `JMSProducer` with the number of milliseconds you want messages to be delayed. (Note that, confusing as it is, you can not use the `setJMSDeliveryTime` method on the Message object.) In JMS 1.1, some JMS implementations support proprietary headers for the same effect.
It's a quite common practice, but it has a major drawback in practical use, when the delay is longer: There's no (standardized) way to access the delayed messages: The `QueueBrowser` doesn't return them until their time has come. If you need more control, you're better off with polling a database.
Problem
I'm looking into a message queue solution where some messages need to be delivered without delay, and other messages need to be delivered at a specified time. The delay is anywhere from hours to a week or two. I have access to a JMS message Queue, but I'm questioning whether it is a good idea to put messages on the queue with long delays. Is delaying messages a common practice? Is using the QueueBrowser to peek at the messages and cherry picking the messages at the right time a viable solution (assuming the message as the delivery date in it)? Is there another solution (other than putting the messages in the database with a time stamp) and periodically querying the database?