Connection definition administration in Java

This section shows you how to create, alter, and delete connection definitions in Java.

Creating a connection definition

To create a connection definition, create an administration message and send it to the administration queue. Before any attempt is made to use the connection, you must receive a reply to indicate successful creation of a connection definition. Indeterminate behavior may result if an attempt is made to use a connection before receiving such a reply.

To create a connection definition, use the examples.config.CreateConnectionDefinition example. A connection definition administration message has a number of methods to help create the message correctly. First of all, create an MQeConnectionAdminMsg:

MQeConnectionAdminMsg connectionMessage = new MQeConnectionAdminMsg();

On creating the connection administration message, set the name of the resource you want to work on:

connectionMessage.setName("RemoteQM");

Now, set the information in the administration message that sets the action to create, and provides the information for the route to our remote queue manager:

connectionMessage.create(
                "com.ibm.mqe.adapters.MQeTcpipHistoryAdapter:127.0.0.1:8082",
                null,
                null,
                "Default Channel",
                "Example connection");

There are a number of things to note about the information passed to the create method:

We now need to add information to the administration message that determines which queue manager receives the administration message.

connectionMessage.setTargetQMgr("LocalQM");

Specify that you want to receive a reply, if using the Msg_Style_Datagram, indicate that no reply was required. The reply indicates success or failure of the administrative action.

connectionMessage.putInt(MQe.Msg_Style, MQe.Msg_Style_Request);

The queue and queue manager that receives the reply, this may not necessarily be the queue manager that created and sent the administration message. Using the default administration reply queue allows you to use the definition of the String provided in the MQe class. Also, the reply must arrive on the local queue.

connectionMessage.putAscii(MQe.Msg_ReplyToQ, MQe.Admin_Reply_Queue_Name);
connectionMessage.putAscii(MQe.MSG_ReplyToQMgr, "LocalQM");

Add a unique identifier to the message before putting it onto the administration queue. This allows you to identify the appropriate reply message. Use the system time to do this.

String match = "Msg" + System.currentTimeMillis();
connectionMessage.putArrayOfByte(MQe.Msg_CorrelID, match.getByte());

You can now put the administration message to the default administration queue. The fourth parameter allows for an MQeAttribute to be specified with the fifth parameter allowing for an identifier that allows you to undo the put. As neither is required, specify null and zero respectively.

queueManager.putMessage("LocalQM", MQe.Admin_Queue_Name, 
									connectionMessage, null, 0);

Before we can safely use the connection definition we need to ensure it has been correctly created and must, therefore, wait for a reply. The examples specifies that the reply should be sent to the queue manager, LocalQM, on the default administration reply queue. Create a filter using the correlation Id to get the correct reply:

MQeFields filter = new MQeFields();
filter.putArrayOfByte(MQe.Msg_CorrelID, match.getBytes());

Now, using the filter, wait for a reply message on the default administration reply queue. The return from the waitForMessage method gives a MQeMsgObject. Cast that to an MQeAdminMsg. The fourth parameter, which is set to null may be used for an MQeAttribute. This is set to null as this example does not use security. The zero passed in parameter five is for a confirm Id (also unused) that may be used in an undo operation. The last parameter defines how long to wait in milliseconds. This example waits for three seconds.

// all on one line
MQeAdminMsg response = (MQeAdminMsg) 
					queueManager.waitForMessage(queueManagerName,
                    MQe.Admin_Reply_Queue_Name,
                    filter,
                    null,
                    0,
                    3000);

Once you receive the reply, check to make sure we have a successful return code. There is additional checking within the example, for the purposes of this manual we just look at the successful return. As can be seen, there is a useful method on the administration message which returns a return code to us for easy checking.

switch (response.getRC()) {
                case MQeAdminMsg.RC_Success :
                    System.out.println("connection created");
                    break;

·
·
·

Altering and deleting connection definitions

Connection definitions define the network for WebSphere MQ Everyplace and therefore great care should be taken when altering or deleting them. It is strongly recommended that when altering or deleting a connection definition one should ensure there is no activity on the network that may be using that connection definition.

As with creating a connection definition, to alter or delete a connection definition, use an administration message. The approach is the same as for creating a connection definition, with a different action being used for the administration message. For example, to update a connection definition, use the following method:

updateMessage.update(
"com.ibm.mqe.adapters.MQeTcpipHttpAdapter:127.0.0.1:8083",
null, null, "DefaultChannel", "Altered Example Connection");

In order to delete a connection definition, all that is required is the resource name and the relevant action being set. Use the following method:

deleteMessage.setAction(MQeAdminMsg.Action_Delete);


© IBM Corporation 2002. All Rights Reserved