ActiveMQ - How do I ignore undelivered messages

183 Views Asked by At

I have a queue producer(NON_PERSISTENT) and a queue consumer connected to my ActiveMQ server. If a producer sends a message to a queue while the consumer is not connected to ActiveMQ, it seems it is stored and delivered when the consumer is up and connected to ActiveMQ.

I want ActiveMQ to ignore the message if the consumer is not connected at the time of delivery. How can I achieve this?

Thanks in advance.

1

There are 1 best solutions below

0
On

Use a topic instead of a queue - this is the default behaviour for topics (unless a durable subscriber is used).

Otherwise, for queues, you can set a message expiry when sending the message. It will be discarded if not read within that time frame. Make sure to set enough time frame so that clock sync issues between servers won't be a factor. Let's say 2 minutes or so.