Specify a range of ports for IBM MQ classes for Java client connections

We can specify a port, or a range of ports, that an application can bind to in either of two ways.

When an IBM MQ classes for Java application attempts to connect to an IBM MQ queue manager in client mode, a firewall might allow only those connections that originate from specified ports or range of ports. In this situation, we can specify a port, or a range of ports, that the application can bind to. We can specify the port(s) in the following ways:

  • We can set the localAddressSetting field in the MQEnvironment class. Here is an example:
    MQEnvironment.localAddressSetting = "192.0.2.0(2000,3000)";
    
  • We can set the environment property CMQC.LOCAL_ADDRESS_PROPERTY. Here is an example:
    (MQEnvironment.properties).put(CMQC.LOCAL_ADDRESS_PROPERTY,
                                   "192.0.2.0(2000,3000)");
    
  • When we can construct the MQQueueManager object, we can pass a properties hashtable containing a LOCAL_ADDRESS_PROPERTY with the value "192.0.2.0(2000,3000)"

In each of these examples, when the application later connects to a queue manager, the application binds to a local IP address and port number in the range 192.0.2.0(2000) to 192.0.2.0(3000).

In a system with more than one network interface, we can also use the localAddressSetting field, or the environment property CMQC.LOCAL_ADDRESS_PROPERTY, to specify which network interface must be used for a connection.

Connection errors might occur if you restrict the range of ports. If an error occurs, an MQException is thrown containing the IBM MQ reason code MQRC_Q_MGR_NOT_AVAILABLE and the following message:
Socket connection attempt refused due to LOCAL_ADDRESS_PROPERTY restrictions
An error might occur if all the ports in the specified range are in use, or if the specified IP address, host name, or port number is not valid (a negative port number, for example). Parent topic: Operations on queue managers