Opening and closing objects

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

To perform any of the following operations, you must first open the relevant WebSphere 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 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, you 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 WebSphere MQ object that you 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 WebSphere MQ objects, see Objects.

You 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. You can also open a queue for browsing and removing messages at the same time.

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

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