tags:

views:

28

answers:

1

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

How to get message count in MSMQ on another machine, in the same domain (programmatically via C#)?

Note I: My main problem is: I can not even connect to the remote queue.

Note II:

1 - "FormatName:DIRECT=TCP:server2.domain.com\private$\qname" did not work.

2 - "server2.domain.com\private$\qname" did not work.

3 -

using (var q = new MessageQueue(Properties.Settings.Default.MessageQueuePath)) { ... } 

did not work.

4 - This:

var q = MessageQueue.GetPrivateQueuesByMachine(Properties.Settings.Default.MessageQueueMachineName).FirstOrDefault();

if (q != null)
    using (q)
    {
        q.Path = Properties.Settings.Default.MessageQueuePath;
        q.SetPermissions(
            Properties.Settings.Default.MessageQueueUser,
            (MessageQueueAccessRights)Properties.Settings.Default.MessageQueuePermission);
        q.UseJournalQueue = false; // commented or not

        var allMessages = q.GetAllMessages();

        if (allMessages != null && allMessages.LongLength > 0) len = allMessages.LongLength;
    }

did not work.

A: 

Hi Kaveh, Counting the number of messages using GetAllMessages is a problematic method, because it peeks all the messages in the queue before counting them - which can be very time and space consuming for queues containing thousands of messages. Basically, the best method is to use MSMQ Admin APIs (performance counters can work too if you don't have too many queues). You are welcome to see my blog posts on the subject at http://yoelarnon.wordpress.com/2004/12/07/counting-the-number-of-messages-in-a-queue/ and yoelarnon.wordpress.com/2005/03/21/counting-messages-in-queue-the-net-version/ .

The immediate issue with your code, however, seems to be the use of DIRECT=TCP format name with DNS name. Try using FormatName:DIRECT=OS:server2.domain.com\private$\qname . See more at msdn.microsoft.com/en-us/library/ms700996(VS.85).aspx .

Hope that helps, Yoel

www.msmq.biz

Yoel Arnon
Thanks; I am looking at them. Yet my main problem is in connecting to the remote queue :(
Kaveh Shahbazian