You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@activemq.apache.org by skvsree <sk...@gmail.com> on 2013/12/17 09:58:30 UTC
Get Count of messages in the queue using NMS
Hi,
I am trying to get the number of messages left in the queue, but I find
it very tricky. Below is the code I am using, but the still the count is
wrong.
long qdepth = 0;
var browser = _session.CreateBrowser(_queue);
var messagesInQ = browser.GetEnumerator();
var list = new List<string>();
while (messagesInQ.MoveNext())
{
var message = messagesInQ.Current as IMessage;
if (message == null ||
list.Contains(message.NMSMessageId))
{
break;
}
list.Add(message.NMSMessageId);
qdepth++;
}
I am finding duplicate MessageIds as well in this case.
--
View this message in context: http://activemq.2283324.n4.nabble.com/Get-Count-of-messages-in-the-queue-using-NMS-tp4675616.html
Sent from the ActiveMQ - User mailing list archive at Nabble.com.
Re: Get Count of messages in the queue using NMS
Posted by Timothy Bish <ta...@gmail.com>.
On 12/17/2013 03:58 AM, skvsree wrote:
> Hi,
> I am trying to get the number of messages left in the queue, but I find
> it very tricky. Below is the code I am using, but the still the count is
> wrong.
> long qdepth = 0;
> var browser = _session.CreateBrowser(_queue);
> var messagesInQ = browser.GetEnumerator();
> var list = new List<string>();
> while (messagesInQ.MoveNext())
> {
> var message = messagesInQ.Current as IMessage;
> if (message == null ||
> list.Contains(message.NMSMessageId))
> {
> break;
> }
> list.Add(message.NMSMessageId);
> qdepth++;
> }
>
> I am finding duplicate MessageIds as well in this case.
>
>
>
>
> --
> View this message in context: http://activemq.2283324.n4.nabble.com/Get-Count-of-messages-in-the-queue-using-NMS-tp4675616.html
> Sent from the ActiveMQ - User mailing list archive at Nabble.com.
>
JMS doesn't really provide a mechanism for getting the queue depth. You
could look at using the StatisticsBrokerPlugin to accomplish this:
http://activemq.apache.org/statisticsplugin.html
--
Tim Bish
Sr Software Engineer | RedHat Inc.
tim.bish@redhat.com | www.fusesource.com | www.redhat.com
skype: tabish121 | twitter: @tabish121
blog: http://timbish.blogspot.com/