Opening and closing objects
To perform any of the following operations, 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, 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, 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 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 WebSphere MQ objects, see WebSphere MQ objects.
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 i5/OS 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.
This chapter introduces opening and closing WebSphere MQ objects, under these headings:
- Opening objects using the MQOPEN call
- Creating dynamic queues
- Opening remote queues
- Closing objects using the MQCLOSE call
- Opening objects using the MQOPEN call
- Creating dynamic queues
- Opening remote queues
- Closing objects using the MQCLOSE call
Parent topic:
Writing a WebSphere MQ application
fg12130_