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中的消息自动过期


基础教程推荐
- Java 实例变量在两个语句中声明和初始化 2022-01-01
- 大摇大摆的枚举 2022-01-01
- 如何在 Spring @Value 注解中正确指定默认值? 2022-01-01
- 多个组件的复杂布局 2022-01-01
- 从 python 访问 JVM 2022-01-01
- 不推荐使用 Api 注释的描述 2022-01-01
- 在 Java 中创建日期的正确方法是什么? 2022-01-01
- Java Swing计时器未清除 2022-01-01
- 如何在 JFrame 中覆盖 windowsClosing 事件 2022-01-01
- 验证是否调用了所有 getter 方法 2022-01-01