Camel中的消息自动过期 [英] Auto expiration of messages in Camel

查看:24
本文介绍了Camel中的消息自动过期的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个实现 Camel 和 ActiveMQ 的系统,用于在一些服务器之间进行通信.我想知道是否有办法在 X 段时间后自动过期并清除发送到队列的消息.由于原始服务器(填充队列)不知道是否有人在接收消息,所以我不希望我的队列增长到太大以至于崩溃.Bonus karma 指向可以提供帮助并提供 java dsl 方式来实现此功能的人.

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.

解决方案

// 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 提供了一种机制让您设置消息的过期时间.看下面两个参考

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

  1. setJMSExpiration(长期过期):每条消息
  2. ActiveMQ:如何设置消息过期:每个目标/每个消息
  1. setJMSExpiration(long expiration): per message
  2. ActiveMQ: How do I set the message expiration: per destionation/per message

这篇关于Camel中的消息自动过期的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆