Feel like a geek and get yourself Ema Personal Wiki for Android and Windows

15 June 2009

MSMQ try-out

MSMQ (Microsoft Message Queuing) seems like a powerful thing:
  • Transactional
  • Robust
  • Works with both COM (vb6!) and .NET
So I decided I should at least know how it works and how I can use it in a project. There are nice .NET wrappers around it, abstracting it away, like NServiceBus, but I should know how it works anyway before using any framework.

Step 1: try out an example from The Bathroom Wall Of Code
Failed. "MSMQ is not installed on this machine". It needs an install of an extra windows component! FAIL! How can I ever use this on my server that is managed by Mordac? Note to self: try out Ayende's Rhino Queues, xcopy install, with no dependency on MSMQ.

Step 2: install MSMQ
Software > Add Windows Component > MSMQ > Installation failed for unclear reasons. Some searching revealed that I had to reset the Distributed Transaction Log by some obscure command. Should of course have thought of that before trying the install. Retry install: fail again. This component has been registered for removal. Ok. Restart machine. Retry again. Now it installs.
Update: John Breakwell blogged about the details and solution of this problem here.

Step 3: Make the queue

MessageQueue q = MessageQueue.Create(@".\Private$\TestQueue");

Step 4: create and configure the queue in 2 applications
MessageQueue q = new MessageQueue(@".\Private$\TestQueue");
q.Formatter = new XmlMessageFormatter(new Type[] { typeof(String) });

Step 5: send message from application 1
q.Send("hi!", "message");

Step 6: receive the message in application 2
Console.WriteLine((string)q.Receive().Body);

Step 7: Watch it work.

9 comments:

Anonymous said...

MSMQ is a great mechanisme! You should also be able to use it through WCF

Derick Bailey said...

perfect timing! I just recommended MSMQ as a way to introduce a needed messaging system, to my team today. I'm forwarding this blog post as a way to get the team started. :)

John Breakwell said...

Hi

I think you should move to a non-Mordacian server management provider :-)

Components such as MSMQ and IIS are not installed by default for various reasons (reduce 'attack surface', reduce number of redundant services, etc.)

Would you mind sharing the details of the install problem/solution please? Strange that you had to mess with DTC to get MSMQ to install.

Cheers
John Breakwell (MSFT)
http://blogs.msdn.com/JohnBreakwell

Unknown said...

I'm afraid Mordac is not our provider (worse).

Installation details:
- During installation, I got an error with the number 0x42c in it (did not record any further details)
- The error was listed on EE
- I looked at the services, listed in the "accepted solution"
- When i tried to start the DTC service, it failed with error -1073737712
- In this KB article, "method 1" solved the problem:
msdtc -resetlog

John Breakwell said...

The DTC dependency is a bit of a strange one for MSMQ as it is not one of the Dependencies defined in the service properties.

The MSMQ service wants it to be running (and I think it tries to start MSDTC if it is not already up) but MSMQ doesn't mind if you stop it later (to avoid having to shut down on a cluster if MSDTC failed over).

Hopefully this new blog post will help out other people in the future:
http://blogs.msdn.com/johnbreakwell/archive/2009/06/16/error-0x42c-when-you-try-to-install-msmq.aspx

Cheers
John Breakwell

John Breakwell said...

Apologies if I'm spamming you - my Dutch-speaking colleague has gone to the gym and I can't work out what the messages are saying when I press the buttons :-)

Unknown said...

Sorry, i changed the language to english.

John Breakwell said...

Thanks but please don't change the Blogger site language on my account.

Unknown said...

The vast cashflow that this blog generates by showing Google ads, came to a sudden halt as Google blocked me for selecting Dutch for my blog language and actually writing in English.
So I was inclined to changed that anyway.