Connections define how to connect one queue manager to another queue manager. Once a connection has been defined, it is possible for a queue manager to put messages to queues on the remote queue manager. The following diagram shows the constituent parts that are required for a remote queue on one queue manager to communicate with a queue on a different queue manager:
Figure 11. Queue manager connections
Communication happens at different levels:
The channel and adapter are specified as part of a connection definition. The transporter is specified as part of a remote queue definition. The following example code shows a method that instantiates and primes an MQeConnectionAdminMsg ready to create a connection:
/** * Setup an admin msg to create a connection definition */ public MQeConnectionAdminMsg addConnection( remoteQMgr adapter, parms, options, channel, description ) throws Exception { String remoteQMgr = "ServerQM"; /* * Create an empty queue manager admin message and parameters field */ MQeConnectionAdminMsg msg = new MQeConnectionAdminMsg(); /* * Prime message with who to reply to and a unique identifier */ MQeFields msgTest = primeAdminMsg( msg ); /* * Set name of queue manager to add routes to */ msg.setName( remoteQMgr ); /* * Set the admin action to create a new queue * The connection is setup to use a default channel. This is an alias * which must have be setup on the queue manager for the connection to * work. */ msg.create( adapter, parms, options, channel, description ); return msg; }
You can connect queue managers in client to server mode. In a client to server configuration, one queue manager acts as a client and the other runs in a server environment. A server allows multiple simultaneous incoming connections (channels). To accomplish this the server must have components that can handle multiple incoming requests. See the WebSphere MQ Everyplace Application Programming Guide for a description of how to run a queue manager in a server environment.
Figure 12 shows the typical connection components in a client to server configuration.
Figure 12. Client to server connections
You use MQeConnectionAdminMsg to configure the client portion of a connection. The channel type is com.ibm.mqe.MQeChannel. Normally an alias of DefaultChannel is configured for MQeChannel. The following code fragment shows how to configure a connection on a client to communicate with a server using the HTTP protocol.
/** * Create a connection admin message that creates a connection * definition to a remote queue manager using the HTTP protocol. Then * send the message to the client queue manager. */ public addClientConnection( MQeQueueManager myQM, String targetQMgr ) throws Exception { String remoteQMgr = "ServerQM"; String adapter = "Network:127.0.0.1:80"; // This assumes that an alias called Network has been setup for // network adapter com.ibm.mqe.adapters.MQeTcpipHttpAdapter String parameters = null; String options = null; String channel = "DefaultChannel"; String description = "client connection to ServerQM"; /* * Setup the admin msg */ MQeConnectionAdminMsg msg = addConnection( remoteQMgr, adapter, parameters, options, channel, description ); /* * Put the admin message to the admin queue (not using assured flows) */ myQM.putMessage(targetQMgr, MQe.Admin_Queue_Name, msg, null, 0 ); }
For details of the adapters supplied with WebSphere MQ Everyplace see the Chapter 2, Adapters, of the WebSphere MQ Everyplace System Programming Guide and Chapter 9 of the WebSphere MQ Everyplace Java Programming Reference.
You can set up a connection so that a queue manager routes messages through an intermediate queue manager. This requires two connections:
The first connection is created by the methods described earlier in this section, either as a client or as a peer connection. For the second connection, the name of the intermediate queue manager is specified in place of the network adapter name. With this configuration an application can put messages to the target queue manager but route them through one or more intermediate queue managers.
You can assign multiple names or aliases to a connection. When an application calls methods on the MQeQueueManager class that require a queue manager name be specified, it can also use an alias.
You can alias both local and remote queue managers. To alias a local queue manager, you must first establish a connection definition with the same name as the local queue manager. This is a logical connection that can have all parameters set to null.
To add and remove aliases use the Action_AddAlias and Action_RemoveAlias actions of the MQeConnectionAdminMsg class. You can add or remove multiple aliases in one message. Put the aliases that you want to manipulated directly into the message by setting the ASCII array field Con_Aliases. Alternatively you can use the two methods addAlias() or removeAlias(). Each of these methods takes one alias name but you can call the method repeatedly to add multiple aliases to a message.
The following snippet of code shows how to add connection aliases to a message:
/** * Setup an admin msg to add aliases to a queue manager (connection) */ public MQeConnectionAdminMsg addAliases( String queueManagerName String aliases[] ) throws Exception { /* * Create an empty connection admin message */ MQeConnectionAdminMsg msg = new MQeConnectionAdminMsg(); /* * Prime message with who to reply to and a unique identifier */ MQeFields msgTest = primeAdminMsg( msg ); /* * Set name of the connection to add aliases to */ msg.setName( queueManagerName ); /* * Use the addAlias method to add aliases to the message. */ for ( int i=0; i<aliases.length; i++ ) { msg.addAlias( aliases[i] ); } return msg; }