JMS主题的生存时间 [英] JMS topic time to live

查看:120
本文介绍了JMS主题的生存时间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发一个由一些模块组成的应用程序.在其中一个模块中,有人创建了一个主题生产者,该主题发布者发布有关主题的消息,但是该模块没有主题使用者来使消息出队.主题生产者使用setTimeToLive()将生存时间属性设置为300000毫秒.

我希望如果没有使用者,消息将在300000毫秒内到期并被释放.

该应用程序已部署在Tomcat 6.0.36上,并使用外部ActiveMQ服务器处理队列和主题.

在主题设置下的"MBeans"选项卡中使用Java VisualVM监视ActiveMQ,我看到变量入队计数"增加了,但是我不知道生存时间设置是否对这些消息生效.我预计计数器"ExpiredCount"会增加,但仍保持固定为0.

是否有办法了解这些消息是否仍留在内存中或是否已释放?

非常感谢!

我在netbeans 7.3上使用j2ee教程示例进行了一些测试,并使用内部glassfish 3.1作为服务器,使用jvisualvm对其进行监视,并按照api的说明进行了所有工作:

JMS API不提供浏览主题的机制.邮件通常会从 它们出现后立即成为主题:如果没有消息使用者可以使用它们,则JMS 提供者将其删除.尽管持久订阅允许消息保留在主题上>在消息使用者未处于活动状态时,却没有检查它们的工具.

我读到glassfish在activeMQ内部使用,所以我希望这对于独立的ActiveMQ服务器也有效.

END EDIT.

解决方案

  • 已连接的客户端(如果尚未过期)可以正常接收消息.
  • 如果已连接的客户端在接收到消息之前花费了太长时间(消息已过期),则服务器可能会将其丢弃(可能是服务器尚未将其推送到客户端的缓冲区中)或可以接收到该消息(如果邮件已在客户端缓冲区中,则可能会发生这种情况.
  • 因此,在您的情况下,如果没有使用者,则消息可能根本不会存储. 排队计数增加,并且过期计数保持为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:

    The JMS API provides no mechanism for browsing a topic. Messages usually disappear from a topic as soon as they appear: if there are no message consumers to consume them, the JMS provider removes them. Although durable subscriptions allow messages to remain on a topic > while the message consumer is not active, no facility exists for examining them.

    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:

    5.1.4 Allowing Messages to Expire
    [...]
    When the message is published, the specified timeToLive is added to the current time to give the expiration time. Any message not delivered before the specified expiration time is destroyed.

    Another quote from the source of javax.jms.Message#getJMSExpiration():

    When a message's expiration time is reached, a provider should discard it. [...]
    Clients should not receive messages that have expired; however, the JMS API does not guarantee that this will not happen.

    So in case of non durable subscribers:

    1. 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.
    2. A connected client receives the message normally, if it has not yet expired.
    3. 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

    Enqueue Count - the total number of messages sent to the queue since the last restart
    Expired Count - the number of messages that were not delivered because they were expired

    Note: A test using JBoss 7 shows that in this case the message does not turn up in the client.

    这篇关于JMS主题的生存时间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

    查看全文
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆