如何获取Topic中的JMS消息数量
如何获取特定 JMS 消息订阅者等待消费的 JMS 消息数量?我使用主题模型(发布/订阅)而不是队列模型。
我希望我的 MDB(消息驱动 bean)能够找出有关它所侦听的主题的信息。说清楚;我希望我的 MDB 获取等待消费的消息数量。
我在 Internet 或文档中找不到任何信息:(
我使用 JBoss Messaging 1.4.4。
How do I get the number of JMS messages waiting to be consumed by a specific JMS message subscriber? I use the Topic model (publish/subscribe) and not the Queue model.
I want my MDB (message driven bean) to be able to figure out this information about the topic it listens to. To be clear; I want my MDB to get the number of messages waiting to be consumed.
I can't find any information in either on Internet or the documentation :(
I use JBoss Messaging 1.4.4.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
AFAIK,JMS 没有指定任何内容来计算目的地中的消息数量。
为此,您需要使用 JMX。查看主题 MBean 的 MBean 属性,位于 TopicMBean#getMessageCounters() 。
MessageCounter
的深度
属性应该就是您要查找的内容。但是,说实话,我不知道您将如何处理这些信息,也不知道这对主题是否有意义。只要消息尚未传递给所有订阅者,并且每个订阅者通常不了解其对等方,消息就会保留在主题中。那么 MDB 如何解释消息计数呢?另请注意,我在 JBoss Messaging 2.0.0.alpha1 的 javadoc。我不知道它是否已被弃用(根据 1.4 中的代码,它没有)或者文档是否不是最新的(毕竟,它是 alpha1 javadoc,我找不到 beta4 的链接) )。
编辑: 正如 skaffman 指出的那样,JBoss Messaging 已更名为 HornetQ。看起来 API 发生了一些变化,但概念仍然适用。文档位于此处。
AFAIK, JMS does not specify anything to count the number of messages in a destination.
You need to use JMX for this. Check out the MBean attributes of the Topic MBean in the documentation and/or the java documentation of TopicMBean#getMessageCounters(). The
depth
attribute ofMessageCounter
should be what you're looking for. But, to be honest, I don't know what you're gonna do with this information and if this has a sense for a Topic. A message will stay in a Topic as long as it hasn't been delivered to all subscribers and each subscriber typically hasn't any knowledge of its peers. So how would one MDB interpret a count of messages?Also note that I couldn't find this MBean in JBoss Messaging 2.0.0.alpha1's javadoc. I don't know if it has been deprecated (according to the code in 1.4, it wasn't) or if the documentation is not up to date (after all, it's the alpha1 javadoc and I couldn't find a link for beta4).
EDIT: As skaffman pointed out, JBoss Messaging has been rebranded as HornetQ. It looks like there have been some changes in the API but concepts still apply. The documentation is here.
但使用 JMS API 则不能。内部 JBossMessaging API 可能会公开该信息,但您必须查看该文档才能找到它。
You can't, not with the JMS API. The internal JBossMessaging API may expose that information, but you'll have to go looking through that documentation to find it.