MSMQ: Is it possible to get the message count of a remote private queue?

4.5k Views Asked by At

I know there are other questions on this, but non actually answer this question.

The Code I have is:

using (var mQ = new MessageQueue(qPath))
            {
                Console.WriteLine("machine: {0}, name : {1}, path : {2}", mQ.MachineName ,mQ.QueueName, mQ.Path);
                Console.WriteLine("message count : {0}",mQ.GetAllMessages().Count());
            }    

When I try the GetAllMessages() on a local queue, of course everything works:

string qPath = @".\private$\queueName";

However, when I try a queue on a remote machine on the same domain which I can ping successfully with just the computer name, I get this error:

Invalid queue path name. at System.Messaging.MessageQueue.ResolveFormatNameFromQueuePath

I've tried:

string qPath = @"remoteMachineName\private$\queueName";
string qPath = @"remoteMachineName.qualified.net\private$\queueName";
string qPath = @"DIRECT=OS:remoteMachineName.qualified.net\private$\queueName";
string qPath = @"DIRECT=OS:remoteMachineName\private$\queueName";
string qPath = @"DIRECT=OS:ip.ad.re.ss\private$\queueName";
string qPath = @"DIRECT=TCP:ip.ad.re.ss\private$\queueName";

All of those give me the same error.

The documentation on the web states that private queues CAN be found IF you know the full "path".

Is this true? if so, how do compile the full path??

cheers

3

There are 3 best solutions below

1
John Breakwell On

The exception shows that the path name can't be converted into a format name for some reason. Try creating the queue with a format name

http://msdn.microsoft.com/en-us/library/ch1d814t.aspx

Like, for example, Formatname:DIRECT=OS:ip.ad.re.ss\private$\queueName

Cheers John

0
Saleh On

Visit this page

"FormatName:Direct=OS:machinename\\private$\\queue"
0
Peter Ritchie On

Yeah, you're missing the FormatName. e.g. "FormatName:Direct=OS:localhost\private$\messages"