Is there any way to listen whether a jms queue element is dequeued within a specific time period

StackOverflow https://stackoverflow.com/questions/21549141

  •  06-10-2022
  •  | 
  •  

Question

Currently I am working on an app which has 2 process.

One to enqueue message to a JMS quque. And another process which have a listener to listen to that jms quque that means dequeue from that jms queue.

If an enqueued element is not dequeued within a specific time period I need to know that from process1. There might be case when process 2 is not running. So this situation may rise when I enqueued an element which is not dequeued.

Currently I am handling this situation using a Queue Browser.

Is there any better way to do this.

Was it helpful?

Solution

I don't know if it's "better" (depends on your requirements) but...

The JMS contract says expired messages should be discarded but some (many?) brokers, such as ActiveMQ can send expired messages to a dead letter queue. So one way might be to send the messages with a time to live; you can then listen for expired messages on the DLQ (and requeue them after). Of course, you'd lose message order then and it might be a little brittle in that messages might expire because the consumer is slow rather than dead.

Another, probably better, alternative would be to have the consumer send a heartbeat (e.g. containing the number of messages processed) from time to time back to the producer on a different queue, and have the producer react when he receives no heartbeat (or the counter doesn't increment as expected).

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