Creating a Queue

All queues, either public or private, are created by calling the MSMQQueueInfo object's Create method. For a description of public and private queues, see Message Queues.

The only queue property required to create the queue is PathName. This property tells 1) MSMQ where to store the queue's messages, 2) whether the queue is public or private, and 3) the name of the queue. Once the queue is created, the MSMQQueueInfo object's returned FormatName property is used to open the queue. For a description of MSMQ pathnames and queue format names, see Referencing a Queue.

    To create a queue
  1. Determine which computer will hold the messages for the queue. The computer's machine name is part of the queue's MSMQ pathname (PathName). For private queues, the local computer must be specified.
  2. Determine whether the queue should be public or private. This tells MSMQ where to register the queue: public queues are registered in Active Directory and private queues are registered on the local computer (private queues can only be registered on the local computer). This information is part of the queue's MSMQ pathname (PathName).
  3. Determine the name for the queue. The queue's name is part of the queue's MSMQ pathname (PathName).

    Note  The MSMQ pathname must be unique in the MSMQ enterprise. This applies to public and private queues.

  4. Determine which queue properties must be set. If a queue property is not specified before calling Create, its default value is used. For a complete list of the queue properties that can be set when a queue is created, see the following Queue Properties section.
  5. Set the queue properties. The only property required to create a queue is PathName; all other queue properties are optional. The PathName property specifies where the queue's messages are stored, if the queue is public or private, and the local name of the queue. To modify properties after the queue is created, see Update.
    qinfo.PathName = "machinename\localname"         
    or
    qinfo.PathName = "machinename\PRIVATE$\localname"
     

    Where qinfo is an MSMQQueueInfo object.

  6. Call Create.
    qinfo.Create
     

Examples

The following two examples show functions used to create a public queue and a private queue. In these examples, two queue properties are specified: PathName and Label.

Note  In these examples, "." is used to indicate the local machine in PathName. For MSMQ servers and independent clients, the local machine is the local computer. However, for MSMQ dependent clients, the local machine is the client's MSMQ server.

For a public queue

Function CreatePublicQueue() As MSMQQueueInfo
   Dim qinfo As New MSMQQueueInfo
   qinfo.PathName = ".\MyQueue" 'Created on local computer.
   qinfo.Label = "Public Queue"
   On Error GoTo ErrorHandler
   qinfo.Create
   Set CreatePublicQueue = qinfo
   Exit Function
ErrorHandler:
   MsgBox "Couldn't create queue. Error: " + Str$(Err.Number)
   MsgBox "Reason:  " + Err.Description
   Set CreatePublicQueue = Nothing
End Function

Sub Test()
    Dim qinfo As MSMQQueueInfo
    Set qinfo = CreatePublicQueue
    If Not qinfo Is Nothing Then
       MsgBox "Queue's format name is: " = qinfo.FormatName
    End If
End Sub
 

For a private queue

Function CreatePrivateQueue() As MSMQQueueInfo
   Dim qinfo As New MSMQQueueInfo
   qinfo.PathName = ".\Private$\MyQueue"        'On local computer.
   qinfo.Label = "Private Queue"
   On Error GoTo ErrorHandler
   qinfo.Create
   Set CreatePrivateQueue = qinfo
   Exit Function
ErrorHandler:
   MsgBox "Couldn't create queue. Error: " + Str$(Err.Number)
   MsgBox "Reason:  " + Err.Description
   Set CreatePrivateQueue = Nothing
End Function

Sub Test()
    Dim qinfo As MSMQQueueInfo
    Set qinfo = CreatePrivateQueue
    If Not qinfo Is Nothing Then
       MsgBox "Queue's format name is: " = qinfo.FormatName
    End If
End Sub
 

Queue Properties

The following optional queue properties can be set by the application when creating the queue:

Authenticate

BasePriority

Journal

JournalQuota

Label

PrivLevel

Quota

ServiceTypeGuid

The following properties are set by MSMQ when it creates the queue. To read these properties, the application must explicitly call the MSMQQueueInfo object's Refresh method before they can be read.

CreateTime (public queues only)

FormatName (public and private queues)

IsTransactional (public and private queues)

ModifyTime (public queues only)

QueueGuid (public queues only)