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.