다음을 통해 공유


How to: Create MessageQueue Component Instances 

You create MessageQueue components when you want to build messaging functionality into your application. MessageQueue components allow you to connect to existing queues, send and receive messages, and otherwise add communication services to your application using 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. If you add an instance of the MessageQueue component to a visual designer (such as the Windows Forms Designer), the component appears in a small area below the bottom border of the form. This is known as the component tray and acts as a place to display all of the nonvisual items associated with the form.

NoteNote

Nonvisual classes that inherit from Component support a visual design surface similar to the component tray, on which your MessageQueue component and other components are arranged. The arrangement of items on this designer is not important, as the interface you see will never be displayed to the application's end users.

For instructions on how to configure MessageQueue components, see Message Queue Configuration Properties.

There are several ways you can create an instance of the MessageQueue component:

  • You can drag an instance of the MessageQueue component from the Components tab of the Toolbox to a form or the Component Designer.

  • You can locate the queue you want in Server Explorer and add it to your designer, creating an instance of the MessageQueue component that is preconfigured to point to that queue.

  • You can create an instance of the MessageQueue component in code.

To create an instance of the MessageQueue component from the Toolbox

  1. Access the Components tab of the Toolbox.

  2. Select the MessageQueue icon and drag it to the designer surface for your form or component.

  3. Configure your component. For more information, see Message Queue Configuration Properties.

To create an instance of the MessageQueue component from Server Explorer

  1. Open Server Explorer. For more information, see How to: Access and Initialize Server Explorer/Database Explorer.

  2. Expand the Servers node and determine whether this node lists the server on which the queue you want resides.

    NoteTip

    If the server you want to view is not listed, you need to add it. For more information, see How to: Access and Initialize Server Explorer/Database Explorer.

  3. Expand the node for the server you want to view, and then locate and expand the Message Queues node beneath it.

    NoteNote

    If the Message Queues node does not expand, the computer on which you are trying to view queues does not have Message Queuing installed. For information on how to install and configure Message Queuing, see your Windows 2000 or Windows NT Message Queuing documentation.

  4. Locate the queue you want to add to your project, and then right-click it.

  5. Click Add to Designer.

  6. Configure your component. For more information, see Message Queue Configuration Properties.

To create an instance of the MessageQueue component programmatically

  1. Create an instance of the MessageQueue class in code and set the Path to determine which existing queue you want your component to reference. Your code might look like this:

    Dim myMQ As New System.Messaging.MessageQueue()
    myMQ.Path = ".\MyNewQueue"
    
    System.Messaging.MessageQueue myMQ =
       new System.Messaging.MessageQueue();
    myMQ.Path = @".\MyNewQueue";
    
    NoteTip

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

    Dim myMQ2 As New System.Messaging.MessageQueue(".\MyNewQueue")
    
    System.Messaging.MessageQueue myMQ2 =
       new System.Messaging.MessageQueue(@".\MyNewQueue");
    
    NoteNote

    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. For more information, see Queue Reference Recommendations.

  2. Configure any other necessary properties for your queue. For more information, see Message Queue Configuration Properties.

See Also

Reference

How to: Access and Initialize Server Explorer/Database Explorer

Concepts

Message Queue Configuration Properties