Specifying a range of ports for client connections

 

When a WebSphere MQ JMS application attempts to connect to a WebSphere MQ queue manager in client mode, a firewall might allow only those connections that originate from specified ports or a range of ports. In this situation, we can use the LOCALADDRESS property of a QueueConnectionFactory or TopicConnectionFactory object to specify a port, or a range of ports, that the application can bind to.

We can set the LOCALADDRESS property by using the WebSphere MQ JMS administration tool, or by calling the setLocalAddress() method in an application. Here is an example of setting the property from within an application:

mqQueueConnectionFactory.setLocalAddress("9.20.0.1(2000,3000)");
When the application connects to a queue manager subsequently, the application binds to a local IP address and port number in the range 9.20.0.1(2000) to 9.20.0.1(3000).

In a system with more than one network interface, we can also use the LOCALADDRESS property to specify which network interface must be used for a connection.

For a direct connection to a broker, the LOCALADDRESS property is relevant only when multicast is used. In this case, we can use the property to specify which local network interface must be used for a connection, but the value of the property must not contain a port number, or a range of port numbers.

Connection errors might occur if you restrict the range of ports. If an error occurs, a JMSException is thrown with an embedded MQException that contains the WebSphere 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).

Because the WebSphere MQ JMS client might create connections other than those required by an application, always consider specifying a range of ports. In general, every session created by an application requires one port and the WebSphere MQ JMS client might require three or four additional ports. If a connection error does occur, increase the range of ports.

Connection pooling, which is used by default in WebSphere MQ JMS, might have an effect on the speed at which ports can be reused. As a result, a connection error might occur while ports are being freed.


uj24400_