Dynamically routing client connection requests

In this scenario, we can dynamically route client connection requests to a target server, based on the name of the channel being used.


Before starting

  • Before you start to use this scenario, make sure that we have completed the prerequisite tasks listed in Getting started with IBM MQ Internet Pass-Thru.
  • Install Java 8.0 JDK.
  • Add the Java bin subdirectory to the PATH environment variable.


If we use the name of the queue manager as the first part of the channel name, you only need to use one MQIPT route to service all connection requests. For example, to connect to QM1, the name of a SVRCONN channel might be QM1.MQIPT.CHANNEL.

The sample exit used in this scenario is SampleOneRouteExit.java. It is provided with MQIPT in the samples/exits subdirectory of the MQIPT installation directory.

The name and location of the compiled exit class file is defined with the MQIPT SecurityExitName and SecurityExitPath properties.

The list of queue manager and server names to be used is read from a configuration file, called SampleOneRouteExit.conf. The exit expects the configuration file to exist in the same directory as the exit class file.

Figure 1. Dynamic one route exit network diagram

This diagram shows the connection flow from the IBM MQ client (called client1.company1.com on port 1415) through MQIPT to three IBM MQ servers (called server1.company2.com, server2.company2.com, and server3.company2.com).


Procedure

To dynamically route client connection requests, complete the following steps:

  1. Create three different queue managers on three separate servers. Each queue manager has a SVRCONN channel named after itself, for example, QM1.MQIPT.CHANNEL on queue manager QM1, and an empty local queue named MQIPT.LOCAL.QUEUE.
  2. On the MQIPT server:
    1. Create a directory called exits in the MQIPT home directory by issuing the following command in a command prompt:
      md C:\mqiptHome\exits
    2. In the C\mqiptHome\exits directory (where C:\mqiptHome is the directory where the mqipt.conf file is located), create a sample configuration file, called SampleOneRouteExit.conf that contains the names of our three queue managers.

      For example, the configuration file could contain the following entries:

      server1.company2.com:1414
      server2.company2.com:1415
      server3.company2.com:1416

      Ensure that there are no blank lines before the first entry in the file and that each entry is a valid server name. If we have used different server names, change these names to match your environment.

      Note that all queue manager names in the list must be unique. If you list the same name more than once, even if the queue managers are on different servers, only the last entry for that name is registered.

    3. Open a command prompt and enter the following commands to compile the exit. You do not have to do this if you have not changed the exit code as the compiled sample exit is supplied with MQIPT.
      C:
      cd \mqipt\samples\exits
      javac -classpath C:\mqipt\lib\com.ibm.mq.ipt.jar;. SampleOneRouteExit.java
    4. Enter the following command to copy the compiled exit class file SampleOneRouteExit.class to the C:\mqiptHome\exits directory:
      copy C:\mqipt\samples\exits\SampleOneRouteExit.class C:\mqiptHome\exits
    5. Edit mqipt.conf and add the following route definition:
      [route]
      ListenerPort=1415
      Destination=server1.company2.com
      DestinationPort=1414
      SecurityExit=true
      SecurityExitName=SampleOneRouteExit
    6. Open a command prompt and start MQIPT:
      C:\mqipt\bin\mqipt C:\mqiptHome -n ipt1
      where C:\mqiptHome indicates the location of the MQIPT configuration file, mqipt.conf, and ipt2 is the name to be given to the instance of MQIPT. The following messages indicate that MQIPT has started successfully:
      5724-H72 (C) Copyright IBM Corp. 2000, 2020 All Rights Reserved
      MQCPI001 IBM MQ Internet Pass-Thru V9.2.0.0 starting
      MQCPI004 Reading configuration information from mqipt.conf
      MQCPI152 MQIPT name is ipt2
      MQCPI021 Password checking has been enabled on the command port
      MQCPI011 The path C:\mqiptHome\logs will be used to store the log files
      MQCPI006 Route 1415 has started and will forward messages to :
      MQCPI034 ....server1.company2.com(1414)
      MQCPI035 ....using MQ protocol
      MQCPI079 ....using security exit C:\mqiptHome\exits\SampleOneRouteExit
      MQCPI080 ......and timeout of 5 seconds
      MQCPI078 Route 1415 ready for connection requests

  3. At a command prompt on the IBM MQ client system, enter the following commands:
    1. Set the MQSERVER environment variable:
      SET MQSERVER=QM1.MQIPT.CHANNEL/TCP/10.9.1.2(1415)
    2. Put a message:
      amqsputc MQIPT.LOCAL.QUEUE QM1
      Hello world 1
      Press Enter twice after typing the message string.The message is routed by MQIPT to QM1 as the SVRCONN channel name starts with QM1.
    3. Get the message from QM1:
      amqsgetc MQIPT.LOCAL.QUEUE QM1
      The message, Hello world 1 is returned.
    4. Reset the MQSERVER environment variable:
      SET MQSERVER=QM2.MQIPT.CHANNEL/TCP/10.9.1.2(1415)
    5. Put a message:
      amqsputc MQIPT.LOCAL.QUEUE QM2
      Hello world 2
      Press Enter twice after typing the message string.The message is routed by MQIPT to QM2 as the SVRCONN channel name starts with QM2.
    6. Get the message from QM2:
      amqsgetc MQIPT.LOCAL.QUEUE QM2
      The message, Hello world 2 is returned.
    7. Reset the MQSERVER environment variable again:
      SET MQSERVER=QM3.MQIPT.CHANNEL/TCP/10.9.1.2(1415)
    8. Put a message:
      amqsputc MQIPT.LOCAL.QUEUE QM3
      Hello world 3
      Press Enter twice after typing the message string.The message is routed by MQIPT to QM3 as the SVRCONN channel name starts with QM3.
    9. Get the message from QM3:
      amqsgetc MQIPT.LOCAL.QUEUE QM3
      The message, Hello world 3 is returned.

Parent topic: Getting started with IBM MQ Internet Pass-Thru