Question

I would like to put messages onto a queue with a date/time as a message property, and pull the message from the queue when that property meets a criteria with respect to the current date.

As an example, suppose that I want to consume the message at 3:00. My idea is to set the property to 3:00 and then have a message selector like event_timestamp <= CURRENT_TIMESTAMP.

I understand that the JMS API's message selector is based on SQL, so I would like to use that in the way that I would query a database, where I might have a keyword like CURRENT_TIMESTAMP or NOW(), or the like. Is there anything similar in the message selector expression syntax, or another way to achieve this sort of result?

Was it helpful?

Solution

As far as I know there is no functions available for selector in JMS specification. Maybe some exists in vendor specific implementation extensions but not in tibco according to the message selector reference.

As the message selector is a fixed parameter for a specific MessageConsumer, you have to craft your selector string with current date (or whatever) and call Session.createConsumer, Session.createDurableSubscriber or Session.createBrowser each time this selector query changes.

I recommend you keep the same connection and session for all your consumers to keep reasonable performance.

Another option is to use a message browser to open messages' property to compute your condition and then decide to consume it effectively if it matches but this idea is definitely a regular polling and it breaks messaging philosophy.

I guess you post a message for processing in the future, after a defined timestamp. Maybe there is another way to implement your requirement thanks to message expiration. In general, a broker can be configured to move expired messages from queue A into another queue B, so it does the job for you: your consumer just listens for messages available on queue B after its expiration only.

OTHER TIPS

If you server is JMS 2.0 compliant, use the delivery delay feature : JMSProducer.setDeliveryDelay(long deliveryDelay).
When you put the message on the queue compute the delay up to the desired time.
The message will become "visible" when the delay expires JMS 2.0 new features

Anything can be put into user defined property of a message. For example a user property MyTimeStamp and value of the property is set as 3.00, then you can use selector where you can have selector as MyTimeStamp='3.00'. The message will be delivered to the waiting consumer as soon as it arrives on a queue. This does not mean that message will be delivered to consumer when the system time is 3PM.

You can use JMSTimestamp which is in Unix time/epoch time (#seconds since 1970). This is a long.

I did not try this but it seems easy.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top