MQOPEN options for removing messages

Three options control the opening of a queue to remove messages from it.

We can use only one of them in any MQOPEN call. These options define whether your program has exclusive or shared access to the queue. Exclusive access means that, until you close the queue, only we can remove messages from it. If another program attempts to open the queue to remove messages, its MQOPEN call fails. Shared access means that more than one program can remove messages from the queue.

The most advisable approach is to accept the type of access that was intended for the queue when the queue was defined. The queue definition involved the setting of the Shareability and the DefInputOpenOption attributes. To accept this access, use the MQOO_INPUT_AS_Q_DEF option. Refer to Table 1 to see how the setting of these attributes affects the type of access that we will be given when we use this option.

Queue attributes Type of access with MQOPEN options
Shareability DefInputOpenOption AS_Q_DEF SHARED EXCLUSIVE
SHAREABLE SHARED shared shared exclusive
SHAREABLE EXCLUSIVE exclusive shared exclusive
NOT_SHAREABLE* SHARED* exclusive exclusive exclusive
NOT_SHAREABLE EXCLUSIVE exclusive exclusive exclusive
Note: * Although we can define a queue to have this combination of attributes, the default input open option is overridden by the shareability attribute. Alternatively:

  • If you know that the application can work successfully even if other programs can remove messages from the queue at the same time, use the MQOO_INPUT_SHARED option. Table 1 shows how, in some cases we will be given exclusive access to the queue, even with this option.
  • If you know that the application can work successfully only if other programs are prevented from removing messages from the queue at the same time, use the MQOO_INPUT_EXCLUSIVE option.

Note:

  1. We cannot remove messages from a remote queue. Therefore we cannot open a remote queue using any of the MQOO_INPUT_* options.
  2. We cannot specify this option when opening a distribution list. For further information, see Distribution lists.

Parent topic: Use the options of the MQOPEN call