AFAIK, JMS does not specify anything to count the number of messages in the recipient.
For this you need to use JMX. Check out the MBean attributes of the MBean topic in the documentation and / or java documentation TopicMBean # getMessageCounters () . The depth MessageCounter should be what you are looking for. But honestly, I do not know what you are going to do with this information, and if it makes sense for the topic. The message will remain in the subject if it has not been delivered to all subscribers, and each subscriber usually does not know their peers. So, how would one MDB interpret the number of messages?
Also note that I could not find this MBean in JBoss Messaging 2.0.0.alpha1 javadoc . I donβt know if it was deprecated (according to the code in 1.4, it isnβt) or if the documentation is not updated (after all, this is the javadoc alpha code and I could not find the link for beta4).
EDIT: As the scaffman noted, JBoss Messaging has been renamed HornetQ. It seems that there have been some changes in the API, but the concepts are still being applied. The documentation is here .
source share