Creating, Deleting, Purging, Creating Instances Of, and Administering Queues

   

You can use the MessageQueue component to create new queues on the Message Queuing network, to delete queues, and to perform some administrative actions on existing queues.

Creating Queues

You create a queue to provide a resource with which your messaging components can interact. For example, suppose you are building an order entry system that places orders into queues as they are received from the sales force or from direct customer interaction on a Web site. You might begin by creating an OrderEntry queue on your Message Queuing enterprise. All the components you create to process orders will interact with this queue.

You can create a public queue on your own computer or any Message Queuing computer to which you have domain or enterprise administrative access rights. You also can create private queues on your local computer only.

It is important to note the difference between creating a queue and creating an instance of the MessageQueue component. When you use the Create constructor, you create a new queue in the Message Queuing network, rather than a component in your project or application. When you create an instance of the MessageQueue component, you create a component inside your project that references an existing queue in the operating system.

You also can configure an installation component to create or locate an existing queue when your application is deployed.

Use the Create method to create a public queue on your computer. Your code should look like this:

 ' Visual Basic       System.Messaging.MessageQueue.Create("myMachine\MyQueue")  // C#       System.Messaging.MessageQueue.Create(@"myMachine\MyQueue"); 

You can use an overload of the Create method to indicate that you want to create a transactional queue. You also can use a period ( . ) in the path to indicate the local machine.

Use the Create method, specifying the necessary syntax, Private$ , to create a private queue on your computer. Your code should look like this:

 ' Visual Basic     System.Messaging.MessageQueue.Create(".\Private$\MyPrivateQueue")  // C#     System.Messaging.MessageQueue.Create(@".\Private$\MyPrivateQueue"); 

To see message queuing information in Windows 2000, follow these steps:

  1. Right-click My Computer on the desktop, and then click Manage.

  2. In the dialog box that appears, expand the Services and Applications node, and then expand Message Queuing. You can find your queue and its messages in this node.

Deleting Queues

You can delete any public or private queues on your local computer, provided that you have the appropriate access rights. To delete a local queue, you must have either full control access rights assigned to you by the queue's owner, or explicit Message Queuing access rights to delete queue- related items from that machine. You cannot delete queues on other computers.

You do not need to purge a queue's messages before deleting the queue. When you delete a queue, all its messages are deleted with it. These messages are not sent to a dead-letter queue and cannot be retrieved.

Use the Delete method to delete the queue you want. Your code should look something like this:

 ' Visual Basic  System.Messaging.MessageQueue.Delete("myMachine\MyQueue")  // C#  System.Messaging.MessageQueue.Delete (@"myMachine\MyQueue"); 

This example shows the queue referenced by path. You also can refer to the queue you want to delete by format name or by label.

Purging Queue Contents

You can use the Purge method to clear the contents of any queue to which you have access rights in the Message Queuing system. For example, suppose you use a journal queue on your local Message Queuing client to record copies of all messages you send out. When that journal reaches its maximum size , you might use the Purge method to clear out the items you no longer need.

Messages stored in journal and dead-letter queues count against the quota for the computer where the queue resides. When the quota is reached, these queues stop accepting new messages. If you use journal and dead-letter queues in your application, it is important to periodically clear messages that are no longer needed from them.

You must have Receive rights in Message Queuing to delete the contents of a queue. When you purge a queue, all the messages it contains are discarded without being sent.

Use the Purge method to clear the contents of the appropriate queue. Your code should look something like this:

 ' Visual Basic  Dim MessageQueue1 as New System.Messaging.MessageQueue  MessageQueue1.Path=".\MyQueue"  MessageQueue1.Purge()  // C#  System.Messaging.MessageQueue MessageQueue1 =  new System.Messaging.MessageQueue();  MessageQueue1.Path=(@"myMachine\MyQueue");  MessageQueue1.Purge(); 

Creating MessageQueue Component Instances

You create MessageQueue components when you want to build messaging functionality into your application. MessageQueue components enable you to connect to existing queues, send and receive messages, and otherwise add communication services to your application with a very small amount of code. For example, suppose you are building an order entry system that places orders into queues as they are received from the sales force or from direct customer interaction on a Web site. You might begin by adding an instance of the MessageQueue component to your project and configuring it to interact with an existing OrderEntry queue on your Message Queuing server.

You can add an instance of the MessageQueue component to Windows Forms, Web Forms, and component classes. MessageQueue components have no visual user interface.

Create an instance of the MessageQueue class in code. Your code might look like this:

 ' Visual Basic  Dim myMQ as New System.Messaging.MessageQueue()  // C#  System.Messaging.MessageQueue myMQ =   new System.Messaging.MessageQueue(); 

Set the Path property to determine which existing queue you want your component to reference. Your code might look like this:

 ' Visual Basic  myMQ.Path = ".\MyNewQueue"  // C#  myMQ.Path = @".\MyNewQueue"; 

You can also do steps one and two in a single step, by using this format:

 ' Visual Basic  Dim myMQ2 as New System.Messaging.MessageQueue(".\MyNewQueue")  // C#  System.Messaging.MessageQueue myMQ2 = new    System.Messaging.MessageQueue(@".\MyNewQueue");" 

You can refer to the queue by the path to the queue, the queue's automatically generated format name, or by the non-unique descriptive label of the queue. Each of these ways of referencing a queue has its advantages and disadvantages.

Configure any other necessary properties for your queue.

MessageQueue Configuration

You can manipulate a variety of properties on the queues and MessageQueue components you create. You can define these properties to help you set values that guide the queue's behavior, or query these properties to retrieve information about a queue with which your component interacts .

You use the Path property to determine what queue your component references. The path can be identified in one of three ways: by the physical path to the queue, by the queue's format name, or by the queue's descriptive label.

Queues can also be classified according to a category. You can use the Category property to determine the type of queue with which you are working. Category is a GUID that the owner of the queue defines. You can either use a GUID-generation tool or make up your own number for the GUID. Category GUIDs do not have to be unique except within a single category. For example, you might define the same category for all your order processing queues. This would enable you to retrieve them all by that GUID.

You use the Formatter property to determine how your message content will be serialized into a message before being sent to a queue, and how it will be extracted from a message after being received from a queue. Setting the Formatter property determines what type of content you can send in a message.

You can use the following properties to control how your component interacts with a queue:

  • DenySharedReceive property Indicates that only one component at a time can look at the messages in a queue. This can be extremely useful in multiuser situations. When DenySharedReceive is set, the first component to peek at or receive messages off a queue is the only component that can perform these operations at that time. When the first component finishes its instance of that queue, it releases the queue either through garbage collection or by calling the Close() method.

  • CanRead and CanWrite properties Determine whether you have read and write access to a particular queue, or set a queue to allow read and write access.

  • MaximumQueueSize and MaximumJournalSize properties Determine the capacity, in kilobytes, of messages that a queue can receive. After this maximum has been reached, the queue no longer accepts messages. By default, the maximum queue size defaults to the queue size the system administrator sets for Message Queuing. If no limit has been set, default queue size is infinite.

  • UseJournalQueue property Determines whether copies of the messages retrieved from the queue are added to a journal queue.

   


Special Edition Using ASP. NET
Special Edition Using ASP.Net
ISBN: 0789725606
EAN: 2147483647
Year: 2002
Pages: 233

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