Programming Message Queuing


Now that you understand the architecture of Message Queuing, you can look into the programming. In the next sections, you see how to create and control queues, and how to send and receive messages.

You also build a small course order application that consists of a sending and receiving part.

Creating a Message Queue

You've already seen how to create message queues with the Computer Management utility. Message queues can be created programmatically with the Create() method of the MessageQueue class.

With the Create() method, the path of the new queue must be passed. The path consists of the host name where the queue is located and the name of the queue. In the example the queue MyNewPublicQueue is created on the local host. To create a private queue the path name must include Private$; for example,\Private$\MyNewPrivateQueue.

After the Create() method is invoked, properties of queue can be changed. For example, using the Label property, the label of the queue is set to Demo Queue. The sample program writes the path of the queue and the format name to the console. The format name is automatically created with a UUID that can be used to access the queue without the name of the server:

 using System; using System.Messaging; namespace Wrox.ProCSharp.Messaging { class Program { static void Main(string[] args) { using (MessageQueue queue = MessageQueue.Create(@".\MyNewPublicQueue")) { queue.Label = "Demo Queue"; Console.WriteLine("Queue created:"); Console.WriteLine("Path: {0}", queue.Path); Console.WriteLine("FormatName: {0}", queue.FormatName); } } } } 



Professional C# 2005
Pro Visual C++ 2005 for C# Developers
ISBN: 1590596080
EAN: 2147483647
Year: 2005
Pages: 351
Authors: Dean C. Wills

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net