Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a way to check how many messages are in a MSMQ Queue?

Tags:

c#

msmq

I was wondering if there is a way to programmatically check how many messages are in a private or public MSMQ using C#? I have code that checks if a queue is empty or not using the peek method wrapped in a try/catch, but I've never seen anything about showing the number of messages in the queue. This would be very helpful for monitoring if a queue is getting backed up.

like image 590
Justin Avatar asked Oct 06 '10 01:10

Justin


People also ask

How do I check MSMQ messages?

Navigate to 'Computer Management (Local) > Services and Applications > Message Queueing > Private Queues' and verify that the two private queues used by my application are visible.

How many messages can MSMQ handle?

Answers. Hi, Based on my research, MSMQ supports messages under 4 MB in size only and each message needs 75 bytes of kernel memory for indexing. The maximum number of messages that MSMQ can hold is based on the size of free space on the volume you have created on the disk in your server.

What is the maximum size of message queue?

You can set the queue manager attribute value in the range 32768 bytes through 100 MB; you can set the queue attribute value in the range 0 through 100 MB.

Is MSMQ obsolete?

Since it exists in Windows 10 and Windows Server 2019, MSMQ will continue to live on until at least 2029—and much longer assuming it isn't removed from future versions of Windows. The System. Messaging namespace lives on in . NET Framework 4.8 (which will be its last release ever, being completely supplanted by .


1 Answers

You can read the Performance Counter value for the queue directly from .NET:

using System.Diagnostics;  // ... var queueCounter = new PerformanceCounter(     "MSMQ Queue",      "Messages in Queue",      @"machinename\private$\testqueue2");  Console.WriteLine( "Queue contains {0} messages",      queueCounter.NextValue().ToString()); 
like image 69
Gary Wright Avatar answered Sep 28 '22 16:09

Gary Wright