Search code examples
c#activemq-classicapache-nms

Apache NMS Getting pending message count


I am trying to get the current number of messages on an activeMQ queue using c#.

I have found this link (that is quite old now) ActiveMQ with C# and Apache NMS - Count messages in queue but enumerating the queue seems like a lot of work for this simple task.

Is this the only way to get the queue message count? If I do use this method is the queue locked while I am enumerating (I don't want to block other readers)?

Thanks, Nick


Solution

  • You can either do the enumeration thing described in that other answer which won't get you the correct answer in many cases or you can use the statistics broker plugin and query that data from the broker.

    With the statistics plugin you can send a message to a control queue and listen for a response on the replyTo destination you provide and get the full statistics of the destination, the caveat being that you need to parse out the data but that shouldn't be that hard.

    The enumeration method won't lock the queue but it won't work the way you want because there is a limit to the depth that the broker will go into a deep queue before stopping when it is feeding a QueueBrowser so you can't be sure you got a correct count. Also using the statistic plugin results in less broker overhead and network traffic since the broker only has to send you one response with the data in it verses sending you all the messages just for the sake of counting.