Compartilhar via


Writing a Message Queuing Application using Visual Basic

 

Applies To: Windows 10, Windows 7, Windows 8, Windows 8.1, Windows Server 2008, Windows Server 2008 R2, Windows Server 2012, Windows Server 2012 R2, Windows Server Technical Preview, Windows Vista

The following list describes what is needed to start writing a sending or receiving application using Microsoft® Visual Basic®.

Note

Not all the possible tasks that can be implemented by your application are covered here. However it does provide a basic understanding of what objects are used to perform the tasks that most sending and receiving applications will need to perform.

  • Make sure that the appropriate object library is referenced in your project. The following object libraries are provided by Message Queuing:

    Microsoft Message Queue 3.0 Object Library: Provided by Windows® XP Professional and the Windows Server 2003 family.

    Microsoft Message Queue 2.0 Object Library: Provided by Windows 2000.

    Microsoft Message Queue 1.0 Object Library: Provided by Windows NT®.

    For information on which library to choose, see Message Queuing Object Libraries.

  • Make sure that you know how Message Queuing is deployed. For example: are the queues you are sending messages to or reading messages from local or remote, is your application going to have access to the directory service at all times, is Message Queuing deployed across different enterprises, is Message Queuing deployed in a mixed mode environment.

  • To send a message to a single destination queue, declare the following variable as Message Queuing objects.

    Dim qinfo As New MSMQQueueInfo  ' Represents the destination queue.  
    Dim q As MSMQQueue              ' Represents opened queue.  
    Dim msg As New MSMQMessage      ' Represents message to be sent.  
    

    For an example of a sending a message to a specific queue, see Visual Basic Code Example: Sending Messages to a Destination Queue.

  • To send a message to multiple destination queues, declare the following variable as Message Queuing objects. Messages can be sent to multiple destination queues using distribution lists, multicast addresses, and multiple-element format names.

    Dim dest As New MSMQDestination    ' Represents multiple destinations.  
    Dim msg As New MSMQMessage         ' Represents message to be sent.  
    

    For examples of sending messages to multiple destination queues, see Sending Messages to Multiple Destinations.

  • To read a message from a queue, declare the following variables as Message Queuing objects.

    Note

    When reading a message, the New keyword cannot be used when declaring the MSMQMessage variable.

    Dim qinfo As New MSMQQueueInfo    ' Represents queue definition.  
    Dim q As MSMQQueue                ' Represents opened queue.  
    Dim msg As MSMQMessage            ' Represents the read message.  
    

    For examples of synchronously reading message in a queue, see Reading Message Examples.