Accessing Outgoing Message Queues

I tried using the COM Interop Example provided in CodeProject at

http://www.codeproject.com/KB/IP/MSMQ.aspx

But I was unable to find Microsoft Message Queue 3.0 Object Library in my Add Reference dialog. I looked online for downloading the library and found the page below.

http://msdn.microsoft.com/en-us/library/windows/desktop/ms703182(v=vs.85).aspx 

and it said that the mqoa.dll, mqoa20.tlb and mqoa10.tlb already exist in Windows xp. I am on Windows 7 and I was able to find these in Windows\System32. I tried registering them using the commands below:

I registered mqoa.dll using

regsvr32 “C:\Windows\System32\mqoa.dll”

I registered the tlbs using:

cd C:\Windows\Microsoft.NET\Framework\v4.0.30139

regtlibv12.exe “C:\Windows\System32\mqoa20.tlb”

As described in http://digital.ni.com/public.nsf/allkb/4F811A9B23F1D46E862566F700615B7A

I fired up Visual Studio again but was unable to find the Microsoft Message Queue 3.0 Object Library in the COM list of Add Reference dialog.

Listing all Queues

I found the following code for listing all queues using System.Management reference. As found in http://stackoverflow.com/questions/6191663/enumerate-all-outgoing-queues-in-msmq-c-sharp

            SelectQuery q = new SelectQuery("Select * From Win32_PerfRawData_MSMQ_MSMQQueue");             ManagementObjectSearcher s = new ManagementObjectSearcher(q);             foreach (var r in s.Get())             {                 Console.WriteLine(r.Properties["Name"].Value);             }

Sample Output:

usdxysgmh1dt119\private$\results

usdxysgmh1dt119\private$\data

usdxysgmh1dt119\private$\low

usdxysgmh1dt119\private$\medium

usdxysgmh1dt119\private$\high

tcp:10.10.10.10\private$\test

usdxysgmh1dt119\private$\vijay

usdxysgmh1dt119

usdxysgmh1dt119\private$\order_queue$

usdxysgmh1dt119\private$\admin_queue$

Computer Queues

The highlighted entry is an outgoing queue.

Examining a System Queue

Source: http://www.yortondotnet.com/2010/04/accessing-outgoing-message-queues-with.html

Here’s the sample code:

            string queueName = GetQueuePath("Test", "10.10.10.10");             MessageQueue remote = new MessageQueue(queueName);             Message testMessage = new Message             {                 Body = "test",                 UseEncryption = false,                 UseJournalQueue = true,                 UseTracing = true,                 UseDeadLetterQueue = true,                 Formatter = new XmlMessageFormatter()             };             remote.Send(testMessage);             MessageQueue monitor = new MessageQueue(queueName, QueueAccessMode.PeekAndAdmin);             Message message = monitor.Peek();             message.Formatter = new XmlMessageFormatter(new String[] { "System.String,mscorlib" });
Console.WriteLine(message.Body);
        public static string GetQueuePath(string queue, string appServer)         {             StringBuilder queueName = new StringBuilder();             queueName.Append("FormatName:Direct=TCP:");             queueName.Append(appServer);             queueName.Append(@"\Private$\");             queueName.Append(queue);             return queueName.ToString();         }

Note that we use same queue name for the remote queue as well as monitor queue, but we create the monitor queue with QueueAccessMode.PeekAndAdmin

If we peek on the remote queue, we will get

System.Messaging.MessageQueueException: Remote computer is not available.

Advertisements

About vijayvepa

I'm a software consultant for Software Specialists Inc. currently working at Philips Respironics, Pittsburgh

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: