Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Auto expiration of messages in Camel

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);
like image 304
Paul Gregoire Avatar asked Jan 15 '12 16:01

Paul Gregoire


1 Answers

JMS provides a mechanism for you to set expiry on messages. Look at the below two references

  1. setJMSExpiration(long expiration): per message
  2. ActiveMQ: How do I set the message expiration: per destionation/per message
like image 93
Aravind Yarram Avatar answered Oct 04 '22 10:10

Aravind Yarram