Simple WCF netMsmq Example (or Step 1 to stop reinventing yet another MSMQ clone)

It's pretty obvious that MSMQ is a bit of a dark art out there. People know it exists, everyone knows someone somewhere that knows a guy who once did something with it, and like practitioners of esoteric arts, the technology is looked upon with distrust. In fact to the point that I see team after team recreate, usually poorly, the infrastructure for a true transactional queuing system, almost always defaulting to some SQL Server implementation.

Let's start with this simple axiom:  DO NOT BUILD YOUR OWN QUEUING SYSTEM UNLESS THAT'S WHAT YOU ARE HIRED TO DO!

By the time you get it designed, debugged, and actually working you'll find that you've just spent your entire dev budget on something that probably doesn't even have half the real features of MSMQ (or any other vendor product). And I am not talking about little used fringe cases you don't need. I am talking about core infrastructure requirements for asynchronous communication infrastructure: Poison message detection, scale out, manageability tools, WMI and monitoring, QoS, and on and on...

Personally I think that the reason that people shy away from MSMQ is simple and clear: the documentation sucks, real working samples are rare, the features have quirks that are not always known, and lastly asynchronous message based solutions are hard. Well, I cannot fix the last item, hard is hard and unless you know how to design a Saga based solution you're going to have trouble. But the others are not hard, they just need explaining and simple working solutions to show how it works. With that being the case I am going to show the most basic of systems, a client and a server leveraging WCF with MSMQ. Attached to this blog is a very simple application that allows a client to fire and forget a WCF message and a service to activate and transactionally process it. I believe that this code and configuration should be clear enough (there's little to it!) and should "just work". Just make sure that you have MSMQ installed on your machine and run Visual Studio in elevated admin mode (so you can create MSMQ objects on your first run).

MSMQ Example.zip