Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a better way to count the messages in an Message Queue (MSMQ)? [duplicate]

I'm currently doing it like this:

MessageQueue queue = new MessageQueue(".\Private$\myqueue");
MessageEnumerator messageEnumerator = queue.GetMessageEnumerator2();
int i = 0;
while (messageEnumerator.MoveNext())
{
    i++;
}
return i;

But for obvious reasons, it just feels wrong - I shouldn't have to iterate through every message just to get a count, should I?

Is there a better way?

like image 539
Damovisa Avatar asked Apr 12 '10 00:04

Damovisa


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.

Is MSMQ asynchronous?

Microsoft Message Queue server, short MSMQ, provides exactly that - guaranteed and reliable message delivery. It provides an easy way to send messages between different applications or to process messages asynchronously.

How can I increase my MSMQ size?

On the Edit menu, click Modify. Type amount of space, and then press ENTER. You must specify the amount of space in kilobytes. Note You must restart the Message Queuing resource for these changes to take effect.


1 Answers

In C# the answer appears to be no - what you are doing is one of the only ways to do this and all the others are similar.

There are ways to do this using WMI or COM - have a look at the MSMQManagement com component. This has a MessageCount property.


I found the following post that may give you some other ideas for slightly better pure C # implementations:

Counting Messages in an MSMQ MessageQueue from C#

While the above appears to be all true, I should note that I've never tried to do this with MSMQ - I've only ever done standard reading from the queues.

like image 139
David Hall Avatar answered Sep 20 '22 15:09

David Hall