jakarta-eejmsactivemq-classicmessage-listener

Restrict time during which is read from a jms queue


I have the following setup:

How do I best limit the MessageListener to only process the messages in the queue during the timeframe?

I would prefer not having a check in the MessageListener checking current system time against the timeframe. It would be good if the messages are not removed from the queue outside of the timeframe.

Thanks


Solution

  • You will need to control this in your application logic.

    Depending on how the MessageListener is implemented, it may be possible to stop/stat it. If this is not possible for you then moving to a message receiver will be your best bet as you can easily choose when to consume the message.

    If neither of these work, you can always choose another ack mode or use of JMS transctions. When a message is consumed, you can decide if you want to fully process the message in the onMessage method. If it is not in the current time frame, you can choose to reject the message, or even hold on to it until you can process it then ack or commit.

    If you choose to reject straight away, you need to ensure there is a retry logic that allows for you to continuously try the same message.