Accessing queues and topics

You can access queues and topics using methods of MQQueueManager or appropriate constructors.

To access queues, use the methods of the MQQueueManager class. The MQOD (object descriptor structure) is collapsed into the parameters of these methods. For example, to open a queue on a queue manager represented by an MQQueueManager object called queueManager, use the following code:

MQQueue queue = queueManager.AccessQueue("qName",
                                         MQC.MQOO_OUTPUT,
                                         "qMgrName",
                                         "dynamicQName",
                                         "altUserId");

The options parameter is the same as the Options parameter in the MQOPEN call.

The AccessQueue method returns a new object of class MQQueue.

When you have finished using the queue, use the Close() method to close it, as in the following example:

queue.Close();
With IBM® MQ .NET, you can also create a queue by using the MQQueue constructor. The parameters are exactly the same as for the accessQueue method, with the addition of a queue manager parameter specifying the instantiated MQQueueManager object to use. For example:

MQQueue queue = new MQQueue(queueManager,
                            "qName",
                            MQC.MQOO_OUTPUT,
                            "qMgrName",
                            "dynamicQName",
                            "altUserId");

Constructing a queue object in this way enables you to write your own subclasses of MQQueue.

Similarly, you can also access topics using the methods of the MQQueueManager class. Use an AccessTopic() method to open a topic. This returns a new object of class MQTopic. When you have finished using the topic, use the Close() method of the MQTopic to close it.

You can also create a topic by using an MQTopic constructor. There are a number of constructors for topics; for more information see MQTopic.NET class.