2

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.

Narendra Verma
  • 2,372
  • 6
  • 34
  • 61

2 Answers2

1

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.

Shashi
  • 14,980
  • 2
  • 33
  • 52
  • Yes, you are right. This may not help me to consume a message at a specified time. I am not sure, if there is any way to integrate Quartz Scheduling concept with JMS. – Narendra Verma Jul 16 '13 at 05:54
1

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

Beryllium
  • 12,808
  • 10
  • 56
  • 86
  • Thanks for replying. I see issue with this approach. If I say a particular message should be processed at 3AM daily. With this approach, I can define message selector property to pick messages at 3AM. Not even before or after. Now, let say there are 10 messages in the queue and all messages are having process time 3AM. Assume that, consumer picks first message at 3AM and it takes 10 minutes to process the message. Now it is 3.10 AM. Where other remaining messages are defined to be processed at 3AM. In this case consumer will never pick other messages as consumer side current time is 3.10 AM. – Narendra Verma Jul 16 '13 at 05:48
  • You can have *n* readers to pick up *n* messages at 3 AM. An alternative is to read all messages matching a selector at 3 AM *before* processing starts. – Beryllium Jul 16 '13 at 07:46