Message Scheduling/Consumption in JMS based on Defined Time

1.5k Views Asked by At

We are using IBM WebSphere MQ as JMS provider with Spring MDP (Message Driven POJO).

Is there any way in JMS where we can configure time related properties in message so that message can be consumed at particular defined time only?

For example, if I am sending three messages into queue M1, M2 and M3. Where, I can configure M2 message property let say 3 AM. And consumer side, consumer can only pick this message @ 3 AM only. If time is not defined, messages should be consumed in a way that JMS Receiver does.

2

There are 2 best solutions below

1
On

JMS 2.0 specification has defines Delivery Delay. With this feature a message producer can specify that a message must not be delivered until after a specified time interval. The message will be available for delivery after the specified time. But this may not help you as you want to a message to be consumed at a specified time. Typically messaging applications are designed to consume messages as soon as they are made available by the messaging provider.

2
On

If you want to process messages at a specified time only, you could create another queue "queue_3am", and schedule a reader to run exactly at 3am.

A variation is to set the timestamp as a message property. So one queue could contain messages to be processed at different points in time. The reader could use message selectors to get relevant messages only.

But you should use a "message pickup timeframe" by adding two timestamps as message properties, for eaxmple set the window to 1 or 5 minutes.

The receiver can use a message selector: A selector is a condition using message properties.

Have a look at this