Microsoft Message Queuing

Microsoft Message Queuing

In my last post “Why Apache ActiveMQ isn’t good for .NET developers?” I described the situation when I couldn’t solve my issue using ActiveMQ. Therefore, I tested another message queue system – Microsoft Message Queuing (MSMQ). Because this system is a Microsoft’s product, it is fully supported by .NET Framework. I don’t know why I was prejudiced against this system in the beginning. In fact, it is a useful and simple message queue system for any .NET developer. Why? See below.

MSMQ  at a glance

Microsoft Message Queuing (MSMQ) is a message queue implementation developed by Microsoft and deployed in its Windows operating systems since Windows NT 4 and Windows 95. Current version 4.0 is released with Windows Vista and Windows Server 2008. It is a very mature system and has a long list of features, like: triggers, connectionless messaging, guaranteed message delivery and many others. For me a very important function is message peeking. In the below example I will show how it works.

Why is it so good? – Example

To answer this question I demonstrate how simple I made my non-trivial system. My issue was to make sample applications: two clients and a server, which are communicating by messages. Detailed description of this issue is in my previous post. I made this system using MSMQ and .NET Framework 3.5 in 5 steps. 1. Installing MSMQ in your Windows system. In Vista: Open “Control Panel -> Programs ->Turn Windows features on or off”. Find and check “Microsoft Message Queue(MSMQ) Server”. MSMQ_install 2. Creating message class I make a class that defines the message structure. You can define any class and send it by MSMQ.

3. Creating Client 1 class This class creates queue if it doesn’t exist and sends message to it.

4. Creating Server class Class creates or open queue receives messages and processes them by worker object. Worker can only process single message. It returns control to server object when processing is done.

5. Creating Client 2 class Class reads all messages in the queue, checks its content and adds it to the list . It is a simple queue monitor.

And that is all. Application works great and does exactly what I wanted. After working with ActiveMQ NMS API I didn’t expect that making this system would go so easily and fast. I’m delighted.

Summary

The main advantages for me are:

  • API is very simple – in several lines of code I have a wide access to queue system.
  • API is well documented (by MSDN).
  • I don’t need any additional server or library – I need only Windows and .NET Framework.
  • Great thing is also that I can send any kind of objects and even streams.
  • I can also look up what is going on with my queues. By “Computer Management” tool in Control Panel as well as by code.
  • It is free.

Main disadvantage:

  • MSMQ is only for Windows users.

Share your opinion and experience with us below or meet us on Twitter: @GOYELLO.

Thanks to Karol Świder for helping me to write this blog post.

IT guy with head full of ideas, strongly oriented on achieving great goals in life. Currently working for GOYELLO, place where I grow.