Fun with MSMQ

Working with MSMQ is pretty simple. A couple of quick google searches will return a nice array of code snippets and tutorials to help you get started. If you prefer books, there are heaps of them out there too, although I'm not really sure how you write entire book which is based soley on MSMQ, but I assure you they do exist. I understand that if you're developing an enterprise application that you'd probably want to use some more complex features of MSMQ, but the basic concept isn't that hard - put a message on the queue, take a message off the queue.. look, here's a diagram which reiterates how simple it all is:

However! There's one small trap which I didn't find mentioned in any of the tutorials, which ended up wasting me a little bit of time when I recently started working with MSMQ. In a nutshell, the trap is this: You cannot check for the existence of a private queue on a remote computer. In my case I'd been developing this code locally, and so all of my calls to MessageQueue.Exists were working perfectly. Every piece of code I'd been using for reference had used MessageQueue.Exists before depositing messages, so while it was quite obviously what was causing my code to fail, removing it felt like a bad idea.

I suppose it makes sense, given that we are talking about private queues, however it seems weird that you can still place messages on the queue, you just can't confirm it's existence first. Maybe this is some sort of security through obfuscation or something, I'm really not sure. Maybe that's where the books come in handy!

Going back and looking at various tutorials, I don't feel bad about taking a bit of troubleshooting before figuring this out, as it's something all of them neglect to mention. With that in mind, let me pause and say this slowly: You cannot verify the existence of a remote queue in your code. You either need to simply close your eyes and hope it works, or make sure all the applications or services which access your queue reside on the same computer, or finally, use public queues if they're suitable to what you're doing.

Link: MSDN Documentation: MessageQueue.Exists
Link: MessageQueueErrorCode Enumeration
Link: Queue Path Names
Link: Direct Format Names

Tags: ,

Posted on Saturday, February 24, 2007 10:21 AM | ASP.NET Web Development C#

Like this? Share it!

No comments posted yet.

Post a comment
Please add 1 and 6 and type the answer here:
Remember me?
Ensure the word in this box says 'orange':