views:

534

answers:

2

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.

+4  A: 

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 of MessageCounter 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.

Pascal Thivent
JBossMessaging 2 has been rebranded as HornetQ, and it's currently at beta 5.
skaffman
Right, I forgot that.
Pascal Thivent
Thanks for your answer!The reason why I want this value is because I connect the topic to a system where I monitor some parameters. One of these is "how many messages are left to process for each topic subscriber".Mayby there is a better way to go?
Rickard
A: 

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.

skaffman