+

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, you must first open the relevant IBM MQ object:

Use the MQOPEN call to open the object, using the options of the call to specify what you want to do with the object. The only exception is if you 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 Putting one message on a queue using the MQPUT1 call ).

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

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

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. You 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 you 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 we have opened. Use the MQCLOSE call to do this.

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