Skip Navigation LinksHome > News Groups > microsoft.public.msmq.programming

Oracle SQL Downloadable Training Videos

count of message in the msmq
From pickup folder performance on 10/25/2006 12:24:01 PM
hi
i know how to read and write from a Message Queue. what i want is to count
the number of messages in a message queue

for example

my queue is like this private$\\eventqueue

and i just wnat to get the the count on the number of messages in the this
queue.

how can i do that ?
Re: count of message in the msmq
From "Frank Boyne" on 10/25/2006 6:21:44 PM
"pickup folder performance"
wrote in message
news:C17E04ED-D95F-4977-B290-AE92B569249E@microsoft.com...
> and i just wnat to get the the count on the number of messages in the
> this
> queue.

There are a number of different ways you can find the number of messages in
a queue.

If you are running on Windows XP or later, then you are using MSMQ 3.0 so
you can use the MSMQManagement COM object and the MessageCount property:
http://msdn.microsoft.com/library/en-us/msmq/html/7b547830-ec3a-4556-ade7-53cb59256f87.asp

If you prefer the C Function API, the equivalent would be MQMgmtGetInfo and
PROPID_MGMT_QUEUE_MESSAGE_COUNT:
http://msdn.microsoft.com/library/en-us/msmq/html/4392cfa3-ad53-42a4-9ddf-0a4f22964c85.asp

If you are running on earlier versions of MSMQ then you can still use the
MQMgmtGetInfo function even though the documentation says that the function
was introduced in MSMQ 3.0. In earlier versions of MSMQ these functions
were part of an unsupported feature called MSMQ Local Admin API (which is
why they are available but not released).

Another way of getting this information is via the performance counters that
MSMQ supports. You can either use PERFMON to view them interactively or you
can use your favourite Perfmon api to access them programmatically or you
can use WMI to access them programmatically.

Re: count of message in the msmq
From om on 10/26/2006 1:54:02 AM
i am using .Net 2.0 and using C#

is there any thing in C# which can do this ?

"Frank Boyne" wrote:

> "pickup folder performance"
> wrote in message
> news:C17E04ED-D95F-4977-B290-AE92B569249E@microsoft.com...
> > and i just wnat to get the the count on the number of messages in the
> > this
> > queue.
>
> There are a number of different ways you can find the number of messages in
> a queue.
>
> If you are running on Windows XP or later, then you are using MSMQ 3.0 so
> you can use the MSMQManagement COM object and the MessageCount property:
> http://msdn.microsoft.com/library/en-us/msmq/html/7b547830-ec3a-4556-ade7-53cb59256f87.asp
>
> If you prefer the C Function API, the equivalent would be MQMgmtGetInfo and
> PROPID_MGMT_QUEUE_MESSAGE_COUNT:
> http://msdn.microsoft.com/library/en-us/msmq/html/4392cfa3-ad53-42a4-9ddf-0a4f22964c85.asp
>
> If you are running on earlier versions of MSMQ then you can still use the
> MQMgmtGetInfo function even though the documentation says that the function
> was introduced in MSMQ 3.0. In earlier versions of MSMQ these functions
> were part of an unsupported feature called MSMQ Local Admin API (which is
> why they are available but not released).
>
> Another way of getting this information is via the performance counters that
> MSMQ supports. You can either use PERFMON to view them interactively or you
> can use your favourite Perfmon api to access them programmatically or you
> can use WMI to access them programmatically.
>
>
>
Re: count of message in the msmq
From "Frank Boyne" on 10/26/2006 3:42:30 PM
"om" wrote in message
news:D216A03F-4E1F-4427-9FE5-D57A2D9C4402@microsoft.com...
> is there any thing in C# which can do this ?

There isn't anything in System.Messaging itself. What I would do is use the
performance counters, WMI and the System.Management namespace, alternatively
you could use the System.Diagnostics namespace and the PerformanceCounter
class to access the counters.

PerformanceCounter class approach:

PerformanceCounter pc = new PerformanceCounter();
pc.CategoryName = "MSMQ Queue";

pc.CounterName = "Messages in Queue";

pc.InstanceName = @"host1\testqueue";

Console.WriteLine (pc.NextValue().ToString());

One thing to watch out for is that NextValue will throw a
System.InvalidOperationException: Instance 'host1\testqueue' does not exist
in the specified Category. if the counter doesn't exist. For example
because the queue does not exist or because it is empty and has been empty
since the MSMQ Queue Manager was initiated (MSMQ only creates counters when
it has to).

WMI & System.Management approach

string path = "Win32_PerfRawdata_MSMQ_MSMQQueue.name='" +
"Host1\\testqueue" + "'";

ManagementObject counter = new ManagementObject (path);

counter.Get ();

uint depth = (uint)counter.GetPropertyValue ("MessagesInQueue");

Notice that the path value is constructed with single quote characters (')
around the queue name (because that's how the WMI Query Language works).
There are a couple of advantages to the WMI/ManagementObject approach. You
don't get an exception when the counter doesn't exist and the whole
System.Management infrastructure gives you a lot more flexibility.


Related Items

Journal Queue problem
Re: MSMQ & Multithreading
MessageQueue.GetLastMessages(int count)... Howto?
Re: Losing message receive events - weird...
Re: Non_Microsoft Message Broker Communication with MSMQ
Re: Message created with MSMQ .NET is not read in C++ VS6
Illegal Format Name
Re: Send a file with MSMQ?
Re: Problem with format of msmq messages, .net
Re: Problem with format of msmq messages, .net
Visitor's Insurance