问题描述
我正在开发一个由一些模块组成的应用程序.在其中一个模块中,有人创建了一个主题生产者,该主题发布者发布有关主题的消息,但是该模块没有主题使用者来使消息出队.主题生产者使用setTimeToLive()
将生存时间属性设置为300000毫秒.
我希望如果没有使用者,消息将在300000毫秒内到期并被释放.
该应用程序已部署在Tomcat 6.0.36上,并使用外部ActiveMQ服务器处理队列和主题.
在主题设置下的"MBeans"选项卡中使用Java VisualVM监视ActiveMQ,我看到变量入队计数"增加了,但是我不知道生存时间设置是否对这些消息生效.我预计计数器"ExpiredCount"会增加,但仍保持固定为0.
是否有办法了解这些消息是否仍留在内存中或是否已释放?
非常感谢!
我在netbeans 7.3上使用j2ee教程示例进行了一些测试,并使用内部glassfish 3.1作为服务器,使用jvisualvm对其进行监视,并按照api的说明进行了所有工作:
我读到glassfish在activeMQ内部使用,所以我希望这对于独立的ActiveMQ服务器也有效.
END EDIT.
javax.jms.Message#getJMSExpiration()
来源中的另一个引号:
因此,对于永久订阅者:
- 服务器将消息发送到每个连接的订户.消息中的到期值设置为当前时间+ TTL".断开连接的订户将不会收到任何东西.
- 已连接的客户端(如果尚未过期)可以正常接收消息.
- 如果已连接的客户端在接收到消息之前花费了太长时间(消息已过期),则服务器可能会将其丢弃(可能是服务器尚未将其推送到客户端的缓冲区中)或可以接收到该消息(如果邮件已在客户端缓冲区中,则可能会发生这种情况.
因此,在您的情况下,如果没有使用者,则消息可能根本不会存储. 排队计数增加,并且过期计数保持为0.过期计数仅在已连接(但空闲)的订户的情况下才增加. /p>
如何找到队列的大小
注意:使用JBoss 7进行的测试表明,在这种情况下,该消息不会在客户端中出现.
I'm working on an application consisting of some modules. In one of those module someone created a topic producer that publishes messages on a topic, but this module hasn't a topic consumer to dequeue the messages. The topic producer sets the time-to-live property to 300000 milliseconds using setTimeToLive()
.
I expect that if there is no consumer, the messages expire within 300000 milliseconds and they are deallocated.
The application is deployed on Tomcat 6.0.36 and it uses an external ActiveMQ server to handle the queues and topics.
Monitoring ActiveMQ with Java VisualVM in the MBeans tab under the topic settings I see that the variable "Enqueue Count" grows, but I don't understand if the time-to-live settings took effect on these messages. I expected to see the counter "ExpiredCount" to increase, but it still remains fixed to 0.
Is there a way to understand if those messages still stay in memory or if they are deallocated?
Thank you very much!
EDIT:
I did some tests using j2ee tutorial examples on netbeans 7.3 using internal glassfish 3.1 as server, monitoring it with jvisualvm and all works as api says:
I read that glassfish uses inside activeMQ so I hope that this is valid also for a standalone ActiveMQ server.
END EDIT.
A quote from Creating Robust JMS Applications:
Another quote from the source of javax.jms.Message#getJMSExpiration()
:
So in case of non durable subscribers:
- The server sends the message to each connected subscriber. The expiry value in the message is set to "current time + TTL". Disconnected subscribers will not receive anything.
- A connected client receives the message normally, if it has not yet expired.
- If a connected client takes too long before receiving a message (the message has expired), it might be discarded by the server (possibly in case the server has not yet pushed it into the client's buffer) or it can be received (possibly in case the message is already in the client's buffer).
So in your case, if there is no consumer, the message is probably not stored at all. Enqueue count is increased, and Expired Count remains at 0. Expired count should only increase in case of a connected (but idle) subscriber.
A quote from How do I find the Size of a Queue
Note: A test using JBoss 7 shows that in this case the message does not turn up in the client.
这篇关于JMS主题的生存时间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!