+

Search Tips | Advanced Search

Opening and closing objects

This information provides an insight into opening and closing IBM MQ objects.

To perform any of the following operations, we must first open the relevant IBM MQ object:

  • Put messages on a queue
  • Get (browse or retrieve) messages from a queue
  • Set the attributes of an object
  • Inquire about the attributes of any object

Use the MQOPEN call to open the object, using the options of the call to specify what we want to do with the object. The only exception is if we want to put a single message on a queue, then close the queue immediately. In this case, we can bypass the opening stage by using the MQPUT1 call (see Put one message on a queue using the MQPUT1 call ).

Before you open an object using the MQOPEN call, we must connect your program to a queue manager. This is explained in detail, for all environments, in Connect to and disconnecting from a queue manager.

There are four types of IBM MQ object that we can open:

  • Queue
  • Namelist
  • Process definition
  • Queue manager

You open all these objects in a similar way using the MQOPEN call. For more information about IBM MQ objects, see Object types.

We can open the same object more than once, and each time you get a new object handle. We might want to browse messages on a queue using one handle, and remove messages from the same queue using another handle. This saves using up resources to close and reopen the same object. We can also open a queue for browsing and removing messages at the same time.

Moreover, we can open multiple objects with a single MQOPEN and close them using MQCLOSE. See Distribution lists for information about how to do this.

When you attempt to open an object, the queue manager checks that we are authorized to open that object for the options that you specify in the MQOPEN call.

Objects are closed automatically when a program disconnects from the queue manager. In the IMS environment, disconnection is forced when a program starts processing for a new user following a GU (get unique) IMS call. On the IBM i platform, objects are closed automatically when a job ends.

It is good programming practice to close objects you have opened. Use the MQCLOSE call to do this.

Use the following links to find out more about opening and closing objects:

Parent topic: Writing a procedural application for queuing


Related concepts

Last updated: 2020-10-04