Accessing queues, topics, and processes in IBM MQ classes for Java
To access queues, topics, and processes, use methods of the MQQueueManager class. The MQOD (object descriptor structure) is collapsed into the parameters of these methods.
Queues
MQQueue queue = queueManager.accessQueue("qName",CMQC.MQOO_OUTPUT);
The accessQueue method returns a new object of class MQQueue.
queue.close();
MQQueue queue = new MQQueue(queueManager,
"qName",
CMQC.MQOO_OUTPUT,
"qMgrName",
"dynamicQName",
"altUserID");
You can specify
a number of options when you create queues. For details of these,
see Class.com.ibm.mq.MQQueue. Constructing a queue object in this way enables you to write your own subclasses of MQQueue.
Topics
MQTopic subscriber =
queueManager.accessTopic("TOPICSTRING","TOPICNAME",
CMQC.MQTOPIC_OPEN_AS_SUBSCRIPTION, CMQC.MQSO_CREATE);
MQTopic publisher =
queueManager.accessTopic("TOPICSTRING","TOPICNAME",
CMQC.MQTOPIC_OPEN_AS_PUBLICATION, CMQC.MQOO_OUTPUT);
When you have finished using the topic, use the close() method to close it.
MQTopic subscriber = new
MQTopic(queueManager,"TOPICSTRING","TOPICNAME",
CMQC.MQTOPIC_OPEN_AS_SUBSCRIPTION, CMQC.MQSO_CREATE);
You can specify a number of options when you create topics. For details of these, see Class com.ibm.mq.MQTopic. Constructing a topic object in this way enables you to write your own subclasses of MQTopic.
A topic must be opened either for publication or for subscription. The MQQueueManager class has eight accessTopic methods and the Topic class has eight constructors. In each case, four of these have a destination parameter and four have a subscriptionName parameter (including two that have both). These can only be used to open the topic for subscriptions. The two remaining methods have an openAs parameter, and the topic can be opened for either publication or subscription depending on the value of the openAs parameter.
To create a topic as a durable subscriber use either an accessTopic method of the MQQueueManager class or an MQTopic constructor that accepts a subscription name and, in either case, set the CMQC.MQSO_DURABLE option.
Processes
MQProcess process =
queueManager.accessProcess("PROCESSNAME",
CMQC.MQOO_FAIL_IF_QUIESCING);
To access a process, use the accessProcess method of the MQQueueManager.
The accessProcess method returns a new object of class MQProcess.
process.close();
MQProcess process =
new MQProcess(queueManager,"PROCESSNAME",
CMQC.MQOO_FAIL_IF_QUIESCING);
Constructing a process object in this way enables you to write your own subclasses of MQProcess.