+

Search Tips | Advanced Search

MQOPEN - Open object

The MQOPEN call establishes access to an object.

The following types of object are valid:


Syntax

MQOPEN (Hconn, ObjDesc, Options, Hobj, CompCode, Reason)


Parameters


General usage notes

  1. The object opened is one of the following:

    • A queue to:

      • Get or browse messages (using the MQGET call)
      • Put messages (using the MQPUT call)
      • Inquire about the attributes of the queue (using the MQINQ call)
      • Set the attributes of the queue (using the MQSET call)

      If the queue named is a model queue, a dynamic local queue is created. See the ObjDesc parameter described in MQOPEN - Open object.

      A distribution list is a special type of queue object that contains a list of queues. It can be opened to put messages, but not to get or browse messages, or to inquire or set attributes. See usage note 8 for further details.

      A queue that has QSGDISP(GROUP) is a special type of queue definition that cannot be used with the MQOPEN or MQPUT1 calls.

    • A namelist to inquire about the names of the queues in the list (using the MQINQ call).
    • A process definition to inquire about the process attributes (using the MQINQ call).
    • The queue manager to inquire about the attributes of the local queue manager (using the MQINQ call).
    • A topic to publish a message (using the MQPUT call)
  2. An application can open the same object more than once. A different object handle is returned for each open. Each handle that is returned can be used for the functions for which the corresponding open was performed.
  3. If the object being opened is a queue other than a cluster queue, all name resolution within the local queue manager takes place at the time of the MQOPEN call. This can include:

    • Resolution of the name of a local definition of a remote queue to the name of the remote queue manager, and the name by which the queue is known at the remote queue manager
    • Resolution of the remote queue manager name to the name of a local transmission queue
    • ( z/OS only) Resolution of the remote queue manager name to the name of the shared transmission queue used by the IGQ agent (applies only if the local and remote queue managers belong to the same queue sharing group)
    • Alias resolution to the name of a base queue or a topic object.

    However, be aware that subsequent MQINQ or MQSET calls for the handle relate solely to the name that has been opened, and not to the object resulting after name resolution has occurred. For example, if the object opened is an alias, the attributes returned by the MQINQ call are the attributes of the alias, not the attributes of the base queue or a topic object to which the alias resolves.

    If the object being opened is a cluster queue, name resolution can occur at the time of the MQOPEN call, or be deferred until later. The point at which resolution occurs is controlled by the MQOO_BIND_* options specified on the MQOPEN call:

    • MQOO_BIND_ON_OPEN
    • MQOO_BIND_NOT_FIXED
    • MQOO_BIND_AS_Q_DEF
    • MQOO_BIND_ON_GROUP

    See Name resolution for more information about name resolution for cluster queues.

  4. An MQOPEN call with the MQOO_BROWSE option establishes a browse cursor, for use with MQGET calls that specify the object handle and one of the browse options. This allows the queue to be scanned without altering its contents. A message that has been found by browsing can be removed from the queue by using the MQGMO_MSG_UNDER_CURSOR option.

    Multiple browse cursors can be active for a single application by issuing several MQOPEN requests for the same queue.

  5. Applications started by a trigger monitor are passed the name of the queue that is associated with the application when the application is started. This queue name can be specified in the ObjDesc parameter to open the queue. See MQTMC2 - Trigger message 2 (character format) for further details.


Read ahead options

When you call MQOPEN with MQOO_READ_AHEAD, the IBM MQ client only enables read-ahead if certain conditions are met. These conditions include:

The following notes apply to the use of read ahead options.

  1. The read ahead options are applicable only when one, and only one, of the MQOO_BROWSE, MQOO_INPUT_SHARED and MQOO_INPUT_EXCLUSIVE options are also specified. An error is not thrown if a read ahead options are specified with the MQOO_ INQUIRE or MQOO_SET options.
  2. Read ahead is not enabled when requested if the options used on the first MQGET call are not supported for use with read ahead. Also, read ahead is disabled when the client is connecting to a queue manager that does not support read ahead.
  3. If the application is not running as an IBM MQ client, read ahead options are ignored.


Cluster queues

The following notes apply to the use of cluster queues.

  1. When a cluster queue is opened for the first time, and the local queue manager is not a full repository queue manager, the local queue manager obtains information about the cluster queue from a full repository queue manager. When the network is busy, it can take several seconds for the local queue manager to receive the needed information from the repository queue manager. As a result, the application issuing the MQOPEN call might have to wait for up to 10 seconds before control returns from the MQOPEN call. If the local queue manager does not receive the needed information about the cluster queue within this time, the call fails with reason code MQRC_CLUSTER_RESOLUTION_ERROR.
  2. When a cluster queue is opened and there are multiple instances of the queue in the cluster, the instance opened depends on the options specified on the MQOPEN call:

    • If the options specified include any of the following:

      • MQOO_BROWSE
      • MQOO_INPUT_AS_Q_DEF
      • MQOO_INPUT_EXCLUSIVE
      • MQOO_INPUT_SHARED
      • MQOO_SET
      the instance of the cluster queue opened must be the local instance. If there is no local instance of the queue, the MQOPEN call fails.
    • If the options specified include none of the options described previously, but include one or both of the following:

      • MQOO_INQUIRE
      • MQOO_OUTPUT
      the instance opened is the local instance if there is one, and a remote instance otherwise (if using the CLWLUSEQ defaults). The instance chosen by the queue manager can, however, be altered by a cluster workload exit (if there is one).
  3. If there is a subscription for the queue, but it is not acknowledged by a full repository, the object is not present in the cluster and the call fails with reason code MQRC_OBJECT_NAME.

For more information about cluster queues, see Cluster queues.


Distribution lists

The following notes apply to the use of distribution lists.

Distribution lists are supported in the following environments: AIX , HP-UX, IBM i, Solaris, Linux , Windows, plus IBM MQ MQI clients connected to these systems.
  1. Fields in the MQOD structure must be set as follows when opening a distribution list:

    • Version must be MQOD_VERSION_2 or greater.
    • ObjectType must be MQOT_Q.
    • ObjectName must be blank or the null string.
    • ObjectQMgrName must be blank or the null string.
    • RecsPresent must be greater than zero.
    • One of ObjectRecOffset and ObjectRecPtr must be zero and the other nonzero.
    • No more than one of ResponseRecOffset and ResponseRecPtr can be nonzero.
    • There must be RecsPresent object records, addressed by either ObjectRecOffset or ObjectRecPtr. The object records must be set to the names of the destination queues to be opened.
    • If one of ResponseRecOffset and ResponseRecPtr is nonzero, there must be RecsPresent response records present. They are set by the queue manager if the call completes with reason code MQRC_MULTIPLE_REASONS.

    A version-2 MQOD can also be used to open a single queue that is not in a distribution list, by ensuring that RecsPresent is zero.

  2. Only the following open options are valid in the Options parameter:

    • MQOO_OUTPUT
    • MQOO_PASS_*_CONTEXT
    • MQOO_SET_*_CONTEXT
    • MQOO_ALTERNATE_USER_AUTHORITY
    • MQOO_FAIL_IF_QUIESCING
  3. The destination queues in the distribution list can be local, alias, or remote queues, but they cannot be model queues. If a model queue is specified, that queue fails to open, with reason code MQRC_Q_TYPE_ERROR. However, this does not prevent other queues in the list being opened successfully.
  4. The completion code and reason code parameters are set as follows:

    • If the open operations for the queues in the distribution list all succeed or fail in the same way, the completion code and reason code parameters are set to describe the common result. The MQRR response records (if provided by the application) are not set in this case.

      For example, if every open succeeds, the completion code is set to MQCC_OK and the reason code is set to MQRC_NONE; if every open fails because none of the queues exists, the parameters are set to MQCC_FAILED and MQRC_UNKNOWN_OBJECT_NAME.

    • If the open operations for the queues in the distribution list do not all succeed or fail in the same way:

      • The completion code parameter is set to MQCC_WARNING if at least one open succeeded, and to MQCC_FAILED if all failed.
      • The reason code parameter is set to MQRC_MULTIPLE_REASONS.
      • The response records (if provided by the application) are set to the individual completion codes and reason codes for the queues in the distribution list.
  5. When a distribution list has been opened successfully, the handle Hobj returned by the call can be used on subsequent MQPUT calls to put messages to queues in the distribution list, and on an MQCLOSE call to relinquish access to the distribution list. The only valid close option for a distribution list is MQCO_NONE.

    The MQPUT1 call can also be used to put a message to a distribution list; the MQOD structure defining the queues in the list is specified as a parameter on that call.

  6. Each successfully opened destination in the distribution list counts as a separate handle when checking whether the application has exceeded the permitted maximum number of handles (see the MaxHandles queue manager attribute). This is true even when two or more of the destinations in the distribution list resolve to the same physical queue. If the MQOPEN or MQPUT1 call for a distribution list would cause the number of handles in use by the application to exceed MaxHandles, the call fails with reason code MQRC_HANDLE_NOT_AVAILABLE.
  7. Each destination that is opened successfully has the value of its OpenOutputCount attribute incremented by one. If two or more of the destinations in the distribution list resolve to the same physical queue, that queue has its OpenOutputCount attribute incremented by the number of destinations in the distribution list that resolve to that queue.
  8. Any change to the queue definitions that would have caused a handle to become invalid had the queues been opened individually (for example, a change in the resolution path), does not cause the distribution-list handle to become invalid. However, it does result in a failure for that particular queue when the distribution-list handle is used on a subsequent MQPUT call.
  9. A distribution list can contain only one destination.


Remote queues

The following notes apply to the use of remote queues.

A remote queue can be specified in one of two ways in the ObjDesc parameter of this call.

In either case:

See the ObjectName and ObjectQMgrName fields described in MQOD - Object descriptor for more information.


Objects


Security

The following notes relate to the security aspects of using MQOPEN.

The queue manager performs security checks when an MQOPEN call is issued, to verify that the user identifier under which the application is running has the appropriate level of authority before access is permitted. The authority check is made on the name of the object being opened, and not on the name, or names, resulting after a name has been resolved.

If the object being opened is an alias queue which points at a topic object, the queue manager performs a security check on the alias queue name, before performing a security check for the topic as if the topic object had been used directly.

If the object being opened is a topic object, whether with ObjectName alone or by using the ObjectString (with or without a basing ObjectName), the queue manager performs the security check by using the resultant topic string, taken from within the topic object specified in ObjectName, and if required concatenating it with that provided in ObjectString, and then finding the closest topic object at or above that point in the topic tree to perform the security check against. This might not be the same topic object that was specified in ObjectName.

If the object being opened is a model queue, the queue manager performs a full security check against both the name of the model queue and the name of the dynamic queue that is created. If the resulting dynamic queue is then opened explicitly, a further resource security check is performed against the name of the dynamic queue.

On z/OS, the queue manager performs security checks only if security is enabled. For more information about security checking, see Set up security on z/OS .


Attributes

The following notes relate to attributes.

The attributes of an object can change while an application has the object open. In many cases, the application does not notice this, but for certain attributes the queue manager marks the handle as no longer valid. These attributes are:

When a handle is marked as invalid, all subsequent calls (other than MQCLOSE) using this handle fail with reason code MQRC_OBJECT_CHANGED. The application must issue an MQCLOSE call (using the original handle) and then reopen the queue. Any uncommitted updates against the old handle from previous successful calls can still be committed or backed out, as required by the application logic.

If changing an attribute causes this to happen, use a special force version of the call.


C invocation

MQOPEN (Hconn, &ObjDesc, Options, &Hobj, &CompCode,
       &Reason);
Declare the parameters as follows:
MQHCONN  Hconn;     /* Connection handle */
MQOD     ObjDesc;   /* Object descriptor */
MQLONG   Options;   /* Options that control the action of MQOPEN */
MQHOBJ   Hobj;      /* Object handle */
MQLONG   CompCode;  /* Completion code */
MQLONG   Reason;    /* Reason code qualifying CompCode */


COBOL invocation

CALL 'MQOPEN' USING HCONN, OBJDESC, OPTIONS, HOBJ, COMPCODE, REASON
Declare the parameters as follows:
**   Connection handle
 01  HCONN     PIC S9(9) BINARY.
**   Object descriptor
 01  OBJDESC.
     COPY CMQODV.
**   Options that control the action of MQOPEN
 01  OPTIONS   PIC S9(9) BINARY.
**   Object handle
 01  HOBJ      PIC S9(9) BINARY.
**   Completion code
 01  COMPCODE  PIC S9(9) BINARY.
**   Reason code qualifying COMPCODE
 01  REASON    PIC S9(9) BINARY.


PL/I invocation

call MQOPEN (Hconn, ObjDesc, Options, Hobj, CompCode, Reason);
Declare the parameters as follows:
dcl Hconn     fixed bin(31);  /* Connection handle */
dcl ObjDesc   like MQOD;      /* Object descriptor */
dcl Options   fixed bin(31);  /* Options that control the action of
                                 MQOPEN */
dcl Hobj      fixed bin(31);  /* Object handle */
dcl CompCode  fixed bin(31);  /* Completion code */
dcl Reason    fixed bin(31);  /* Reason code qualifying CompCode */


High Level Assembler invocation

CALL MQOPEN,(HCONN,OBJDESC,OPTIONS,HOBJ,COMPCODE,REASON)
Declare the parameters as follows:
HCONN     DS      F  Connection handle
OBJDESC   CMQODA  ,  Object descriptor
OPTIONS   DS      F  Options that control the action of MQOPEN
HOBJ      DS      F  Object handle
COMPCODE  DS      F  Completion code
REASON    DS      F  Reason code qualifying COMPCODE


Visual Basic invocation

MQOPEN Hconn, ObjDesc, Options, Hobj, CompCode, Reason
Declare the parameters as follows:
Dim Hconn    As Long 'Connection handle'
Dim ObjDesc  As MQOD 'Object descriptor'
Dim Options  As Long 'Options that control the action of MQOPEN'
Dim Hobj     As Long 'Object handle'
Dim CompCode As Long 'Completion code'
Dim Reason   As Long 'Reason code qualifying CompCode'