JBoss 系列八十七: JBoss 中 JMS 消息设定 TimeToLive 的一个误解

概述

我们在启动JBoss后通常使用如下代码设定消息的TimeToLive

javax.jms.MessageProducer;

MessageProducer msgProducer = null;
session = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
msgProducer = session.createProducer(responseQ);
msgProducer.setTimeToLive(Long.valueOf(messageTtl));

但发现消息超过设定的 messageTtl 时间后仍然在消息队列中,所以有人误解为JBoss 中 对 JMS 消息设定 TimeToLive 没有实现。

原因

误解的本身是对JMS标准没有理解准确,TimeToLive意思是当消息队列上有消费者,且消息超过TimeToLive时间没有被消费者消费,则消息被移除,JBoss被异常到ExpirationQueue。如下摘自https://community.jboss.org/wiki/JBMMessageExpiration:

The setTimeToLive() can be used to expire a JMS message. However, the messages would remain on the given destination beyond the time set to expire, if there are no message listeners.  The messages sent to any destination with having setTimeToLive() attribute may not expire unless there's a message listener attached to given destination.

 

The messages marked to expire are validated and sent to the ExpiryQueue, at the time of processing by the attached message listener. IOW the messages which remain on the destination beyond the expiry limit, would expire (moved to the ExpiryQueue) by the time a listener is attached to the given destination.



转载于:https://my.oschina.net/iwuyang/blog/197176

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值