How to: Create 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 of the components you create to process orders will interact with this queue.

There are two ways you can create a queue: by using the Server Explorer window or by using the Create constructor from your code. You can use Server Explorer or the Windows 2000 Computer Management window to verify that your queue has been created successfully.

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 can also create private queues on your local computer only. For more information on access rights, see Message Queue Security, or see "Access Control for Message Queuing" in the documentation for the Computer Management window.

Note

It is important to note the difference between creating a queue and creating an instance of the MessageQueue component. When you use the Create method, you are creating 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.

To create a queue from Server Explorer

When you add an instance of the MessageQueue component to your Visual Studio project, the system automatically creates the references and import statements you need to access these namespaces and classes.

Right-click the Message Queues node.

Right-click either Public Queues or Private Queues, depending on the type of queue you want to create, and then click Create Queue.

Creating a public message queue can take longer than expected if the domain is large and the domain has many domain controllers. This is because it takes time for the new public queue to replicate from your computer's domain controller to all other domain controllers in the domain. You may experience a delay during this replication process.

To create a public queue programmatically

Right-click the project and select Add Reference. Add a reference to System.Messaging.dll.

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

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

Security Note

When you create a message queue, be aware that the resource may already exist. Another process, perhaps a malicious one, may have already created the resource and have access to it. When you put data in the message queue, the data is available to the other process. For information on existing queues, see How to: Retrieve Queues.

To create a private queue programmatically

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