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
- value & 是什么意思?0xff 在 Java 中做什么? 2022-01-01
- Safepoint+stats 日志,输出 JDK12 中没有 vmop 操作 2022-01-01
- 如何使用WebFilter实现授权头检查 2022-01-01
- Jersey REST 客户端:发布多部分数据 2022-01-01
- Eclipse 插件更新错误日志在哪里? 2022-01-01
- C++ 和 Java 进程之间的共享内存 2022-01-01
- Spring Boot连接到使用仲裁器运行的MongoDB副本集 2022-01-01
- 将log4j 1.2配置转换为log4j 2配置 2022-01-01
- 从 finally 块返回时 Java 的奇怪行为 2022-01-01