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

3

7

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

Christmas answered 5/5, 2011 at 0:51 Comment(4)
Have you checked firewall settings on the remote server? MSMQ needs about 4 ports open, IIRC. Your line string qPath = @"DIRECT=OS:remoteMachineName\private$\queueName"; is what I use when getting the message count from a remote private queue.Papilloma
ah really? dude thank you, I'll try that out and come back to you. You should put your comment as an answer so I can rep it up!Christmas
Have you granted the user running the process where you're trying to enumerate the messages rights to the given MSMQ queue?Singspiel
I'm also having the exact same problem. No solution found, as of yet.Hansom
L
1

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

Lethia answered 5/5, 2011 at 1:9 Comment(1)
Hi, thanks John, that doesn't work. I now get: "The Specified format name does not support the requested operation for example, a direct queue format name cannot be deleted." I'm running the same code as above which is just doing a GetAllMessages()Christmas
K
0

Visit this page

"FormatName:Direct=OS:machinename\\private$\\queue"
Korykorzybski answered 15/5, 2011 at 13:52 Comment(0)
A
0

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

Aston answered 15/5, 2011 at 14:52 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.