Search code examples
jmstibco-ems

Can I compare with the current date for a JMS message selector?


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?


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.