I have a system implementing Camel and ActiveMQ for communication between some servers. I would like to know if there is a way to automatically expire and clear-out messages sent to a queue after X period of time. Since the originating server (filling the queue) wont know if anyone is picking up the messages, I don't want my queue to grow until its so large that something crashes. Bonus karma points to someone who can help and provide the java dsl way to implement this feature.
Solution
// expire message after 2 minutes
long ttl = System.currentTimeMillis() + 120000;
// send our info one-way to the group topic
camelTemplate.sendBodyAndHeader("jms:queue:stats", ExchangePattern.InOnly, stats, "JMSExpiration", ttl);
JMS provides a mechanism for you to set expiry on messages. Look at the below two references
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With