当前位置: 动力学知识库 > 问答 > 编程问答 >

java - 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);

网友答案:

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
网友答案:

Also mind that clocks between client - broker need to be in sync, for the expiry to work properly. If the clocks is not in sync, then the expiry set from the client, may already be expired when the message is received on the broker. Or the client time is ahead of the broker, so the expiry is longer than the 10 secs.

It kinda beats me why the expiry is client time based. So AMQ offers a plugin, to fix this by realigning the time, to be broker based only. See http://activemq.apache.org/timestampplugin.html

网友答案:

Well the setJMSExpiration(long expiration):

is something you MUST not call when you are the client. See my talk on this a bit on the ActiveMQ forum.

http://apache-qpid-developers.2158895.n2.nabble.com/MRG-Java-JMS-Expiration-td7171854.html

分享给朋友:
您可能感兴趣的文章:
随机阅读: