Compartilhar via


Opening Queues

 

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

An application must open a queue before it can send messages to the queue or receive messages from the queue. When the application opens the queue, Message Queuing returns a queue handle that the application can used to perform the following operations:

  • Send messages to one or more (in MSMQ 3.0) destination queues.

  • Peek at or retrieve messages from a single queue.

  • Create cursors for navigating through the queue (Message Queuing COM components provide a single implicit cursor each time a queue is open).

  • Create format names.

  • Close the queue.

In the call to open the queue, the application must specify three pieces of information:

  • The queue format name.

  • The access mode.

  • The share mode.

Format Names

An application uses different kinds of format names to open a queue depending on how you want messages to be routed and on the type of the destination as well as on the type of operation for which the queue is being opened:

  • Direct Format Names are used to send messages directly to a specific computer or receive messages from a local queue without accessing the directory service. When messages are sent directly to a remote queue, Message Queuing provides no routing support.

  • Public format names are used to open public queues and their journals. For examples of public format name syntax, see Public Format Names.

  • Private format names are used to open private queues and their journals. For examples of public format name syntax, see Private Format Names.

  • Distribution list format names (introduced in MSMQ 3.0) are used to send messages to multiple destination queues (distribution lists cannot be used to read messages in a queue). For examples of public format name syntax, see Distribution List Format Names.

  • Multicast address format names (introduced in MSMQ 3.0) are used to send messages to all queues associated with a specific multicast address (multicast addresses cannot be used to read messages in a queue). For examples of multicast addresses forma name syntax, see Multicast Address Format Names.

  • Multiple-element format names (introduced in MSMQ 3.0) are used to send messages to multiple destinations (multiple-element format names cannot be used to read messages in a queue). For examples of multiple-element format name syntax, see Multiple-Element Format Names.

  • Machine format names are used to read messages from the computer journal and dead-letter queues (machine format names cannot be used to send messages to journal and dead-letter queues). For examples of machine format name syntax, see Machine and Connector Format Names.

  • Connector format names are used by connector applications (see C) to read messages from the connector queues on the local connector server (connector format names cannot be used to send messages to connector queues). For examples of connector format name syntax, see Machine and Connector Format Names.

Access Mode

The access mode tells Message Queuing how to open the queue (with send, peek, or receive access). Message Queuing then compares the access mode requested with the registered access rights of the queue that are allowed for the caller and determines whether to grant or deny the application access to the queue.

Share Mode

The share mode of the queue specifies who else can open the queue while your application has it open. The share mode of the queue can be set to MQ_DENY_NONE (the default) or MQ_DENY_RECEIVE_SHARE.

When opening a queue to send messages, always set the share mode of the queue to MQ_DENY_NONE. This allows everyone full access to send, peek at, or retrieve messages from the queue while you have the queue open.

When opening a queue to peek at or retrieve messages, you can specify MQ_DENY_NONE to share the queue with everyone, or you can set the share mode to MQ_DENY_RECEIVE_SHARE so that only you can peek at or retrieve messages until you close the queue (note that other applications can still send messages to the queue). You can also use MQ_DENY_RECEIVE_SHARE to stop others from deleting messages while you have the queue open.

The following error conditions can occur when the access mode is set to MQ_DENY_RECEIVE_SHARE:

  • After Message Queuing opens the queue, an error message is returned if anyone, including you, tries to open the queue with peek or receive access.

  • If you try to open the queue with MQ_DENY_RECEIVE_SHARE and the queue is already open with peek or retrieve access, your call will fail.

More Information

For information on See
How MSMQ opens local queues. Opening Local Queues
How MSMQ opens remote queues. Opening Remote Queues
How MSMQ opens queues with a direct format name. Opening Queues with a Direct Format Name