Click to See Complete Forum and Search --> : How to install msmq?


Johnyjoe
September 19th, 2007, 02:38 AM
Good morning,

Recently I have been asked to use the MessageQueue object in C#
but after I wrote a code that ceates MessageQueue and send a meassge to it I got the error:

"The queue does not exist or you do not have sufficent permissions to perform the opearation"

Can someone please help me?

Thanks.

MadHatter
September 19th, 2007, 01:11 PM
go to add/remove programs, click on the windows components button and scroll through that to find the message queue check box and check it. you may need your windows install CD for it to install.

if its installed, open up your computer management console, and go to your message queue, and make sure your queue's are created there. Its been a while since I've used it but you may need to make sure the permissions are set for it too (I don't have it installed atm so I cant check, but you may have to do that).

Arjay
September 19th, 2007, 04:30 PM
Once you get message queuing installed you'll need to create a queue.

Generally you'll create a private queue and to do this:

Open the Computer Management icon in control panel
Expand the 'Services and Applications' node
Expand the 'Message Queuing' node
Select the private queue node
From there right click, choose 'new' and select 'Private Queue'.
Give the queue a name, set the permissions (if necessary) and press 'OK'.
There are several ways to make a queue connection via the path string.

If you are sending a message to a queue on your domain, you can use the Direct OS form:


//Local (file://local/) machine
"FormatName:DIRECT=OS:.\Private$\MyQueue"

or
//Remote (file://remote/) machine
"FormatName:DIRECT=OS:MachineName\Private$\MyQueue"


If you are sending to a machine outside the domain, you can use the TCP form:


FormatName:DIRECT=TCP:10.5.6.1\Private$\MyQueue


If you leverage serialization, you can send actual C# objects through the queue. All you need is a class that is serializable and wrap it with a Message object. You can send multiple object types (i.e. different classes) through the same queue.

For example, I'm working on a TimeClock system that uses hand scanners to log in employees (Employees enter an Emp# into a machine, put their hand on the machine and the machine validates them - kind of like a fingerprint scanner only the hand is used).

Anyway, I have a service that is located in one domain that polls the scanner to retrieve the succesful/rejected scans, then forwards the 'TimeClock' events to the home office via a message queue located in another domain. In addition to the events, I need to know whether the service and/or connection is offline so I send I ping (or heartbeat) message every minute. I have a service in the home office that reads the messages off the queue and puts them into the database (the ping message just updates a datetime field in the db).

Here's the code that forms the message:


public class TimeClockPing
{
public static Message CreateMessage( Guid serviceID, Guid storeID )
{
return new Message( new TimeClockPing( serviceID, storeID ) );
}


private TimeClockPing( Guid serviceID, Guid storeID )
{
_serviceID = serviceID;
_storeID = storeID;
}

// Private fields and other code removed
}


Here's the code that sends the message:


using( MessageQueue mq = new MessageQueue( AppConfig.Connections.Queue.TimeClockEventQueue ) )
{
mq.Send( TimeClockPing.CreateMessage( _serviceID, _storeID ) );
}


Okay I've probably over answered here, but Message Queuing combined with serialization is really slick. It can greatly simplify code because the message subsystem takes care of the sending/resending, maintaining the connection type of code. If the connection gets dropped in the middle of a send, no problem, the MQ system handles it and the message will get sent when the connection is restored. :D