Operations on queue managers

 


This section describes how to connect to, and disconnect from, a queue manager using WebSphere MQ classes for Java.

 

Setting up the WebSphere MQ environment

Note:
This step is not necessary when using WebSphere MQ classes for Java in bindings mode. In that case, go directly to Connecting to a queue manager. Before you use the client connection to connect to a queue manager, set up the MQEnvironment.

The C based WebSphere MQ clients rely on environment variables to control the behavior of the MQCONN call. Because Java applets have no access to environment variables, the Java programming interface includes a class MQEnvironment. This class allows you to specify the following details that are to be used during the connection attempt:

To specify the channel name and host name, use the following code:

MQEnvironment.hostname = "host.domain.com";
MQEnvironment.channel  = "java.client.channel";

This is equivalent to an MQSERVER environment variable setting of:

"java.client.channel/TCP/host.domain.com".

By default, the Java clients attempt to connect to a WebSphere MQ listener at port 1414. To specify a different port, use the code:

MQEnvironment.port = nnnn;

The user ID and password default to blanks. To specify a non-blank user ID or password, use the code:

MQEnvironment.userID   = "uid";  // equivalent to env var MQ_USER_ID
MQEnvironment.password = "pwd";  // equivalent to env var MQ_PASSWORD

 

Connecting to a queue manager

You are now ready to connect to a queue manager by creating a new instance of the MQQueueManager class:

MQQueueManager queueManager = new MQQueueManager("qMgrName");

To disconnect from a queue manager, call the disconnect() method on the queue manager:

queueManager.disconnect();

If you call the disconnect method, all open queues and processes that you have accessed through that queue manager are closed. However, it is good programming practice to close these resources explicitly when you finish using them. To do this, use the close() method.

The commit() and backout() methods on a queue manager replace the MQCMIT and MQBACK calls that are used with the procedural interface.

 

WebSphere is a trademark of the IBM Corporation in the United States, other countries, or both.

 

IBM is a trademark of the IBM Corporation in the United States, other countries, or both.