Click here to Skip to main content
15,884,628 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,

I have a requirement to get the disk used by the message queue in C# as incoming volume of queue is very high. Is there any way to get MSMQ disk usage.

What I have tried:

I have found way to get number of messages in queue, but nothing on size of queue.
Posted
Updated 19-Jul-19 22:31pm

1 solution

MessageQueue class has a GetAllMessages() which returns an array of Message instances.
Once you get this array, initialize a counter variable to zero. Then loop through all messages in the array, and use the BodyStream property of the Message instance to get a reference to the underlying stream. Finally, use the Length property of the stream to get its length (in bytes), and add it to the counter.
C#
Message[] messages = queue.GetAllMessages();
long total = 0;
foreach (Message message in messages)
{
   total += message?.BodyStream?.Length;
}
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900