Auto expiration of messages in Camel(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
- setJMSExpiration(长期过期):每条消息
- ActiveMQ:如何设置消息过期:每个目标/每个消息
- setJMSExpiration(long expiration): per message
- ActiveMQ: How do I set the message expiration: per destionation/per message
这篇关于Camel中的消息自动过期的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:Camel中的消息自动过期


基础教程推荐
- 无法使用修饰符“public final"访问 java.util.Ha 2022-01-01
- Java:带有char数组的println给出乱码 2022-01-01
- “未找到匹配项"使用 matcher 的 group 方法时 2022-01-01
- Java Keytool 导入证书后出错,"keytool error: java.io.FileNotFoundException &拒绝访问" 2022-01-01
- 设置 bean 时出现 Nullpointerexception 2022-01-01
- 减少 JVM 暂停时间 >1 秒使用 UseConcMarkSweepGC 2022-01-01
- 如何使用 Java 创建 X509 证书? 2022-01-01
- FirebaseListAdapter 不推送聊天应用程序的单个项目 - Firebase-Ui 3.1 2022-01-01
- 在 Libgdx 中处理屏幕的正确方法 2022-01-01
- 降序排序:Java Map 2022-01-01