Set up the IBM MQ environment for IBM MQ classes for Java

For an application to connect to a queue manager in client mode, the application must specify the channel name, host name, and port number.

Note: The information in this topic is relevant only if the application connects to a queue manager in client mode. It is not relevant if it connects in bindings mode. See: Connection modes for IBM MQ classes for JMS

We can specify the channel name, host name, and port number in one of two ways: either as fields in the MQEnvironment class or as properties of the MQQueueManager object.

If you set fields in the MQEnvironment class, they apply to your whole application, except where they are overridden by a properties hash table. To specify the channel name and host name in MQEnvironment, use the following code:
MQEnvironment.hostname = "host.domain.com";
MQEnvironment.channel = "java.client.channel";
This is equivalent to setting an MQSERVER environment variable:
"java.client.channel/TCP/host.domain.com".
By default, the Java clients attempt to connect to an IBM MQ listener at port 1414. To specify a different port, use the following code:
MQEnvironment.port = nnnn;
where nnnn is the required port number

If you pass properties to a queue manager object at its creation, they apply only to that queue manager. Create entries in a Hashtable object with keys of hostname, channel, and, optionally, port, and with appropriate values. To use the default port, 1414, we can omit the port entry. Create the MQQueueManager object by using a constructor that accepts the properties hash table.


Identifying a connection to the queue manager by setting an application name

An application can set a name that identifies its connection to the queue manager. This application name is shown by the DISPLAY CONN MQSC/PCF command (where the field is called APPLTAG ) or in the IBM MQ Explorer Application Connections display (where the field is called App name ).

Application names are limited to 28 characters, so longer names are truncated. If an application name is not specified, a default is provided. The default name is based on the invoking (main) class, but if this information is not available, the text IBM MQ Client for Java is used.

If the name of the invoking class is used, it is adjusted to fit by removing leading package names, if necessary. For example, if the invoking class is com.example.MainApp, the full name is used, but if the invoking class is com.example.dictionaryAndThesaurus.multilingual.mainApp, the name multilingual.mainApp is used, because it is the longest combination of class name and rightmost package name that fits into the available length.

If the class name itself is more than 28 characters long, it is truncated to fit. For example, com.example.mainApplicationForSecondTestCase becomes mainApplicationForSecondTest.

To set an application name in the MQEnvironment class, add the name to the MQEnvironment.properties hash table, with a key of MQConstants.APPNAME_PROPERTY, by using the following code:
MQEnvironment.properties.put(MQConstants.APPNAME_PROPERTY, "my_application_name");

To set an application name in the properties hash table that is passed to the MQQueueManager constructor, add the name to the properties hash table with a key of MQConstants.APPNAME_PROPERTY.


Overriding properties specified in an IBM MQ client configuration file

An IBM MQ client configuration file can also specify properties that are used to configure IBM MQ classes for Java. However, properties specified in an IBM MQ MQI client configuration file apply only when an application connects to a queue manager in client mode.

If required, we can override any attribute in an IBM MQ configuration file in any of the following ways. The options are shown in order of precedence.

  • Set a Java system property for the configuration property.
  • Set the property in the MQEnvironment.properties map.
  • On Java5 and later releases, set a system environment variable.

Only the following attributes in an IBM MQ client configuration file are relevant to IBM MQ classes for Java. If you specify or override other attributes, it has no effect.

Stanza Attribute
ClientExitPath stanza of the client configuration file ExitsDefaultPath
ClientExitPath stanza of the client configuration file ExitsDefaultPath64
ClientExitPath stanza of the client configuration file JavaExitsClasspath
MessageBuffer stanza of the client configuration file MaximumSize
MessageBuffer stanza of the client configuration file PurgeTime
MessageBuffer stanza of the client configuration file UpdatePercentage
TCP stanza of the client configuration file ClntRcvBufSize
TCP stanza of the client configuration file ClntSndBufSize
TCP stanza of the client configuration file Connect_Timeout
TCP stanza of the client configuration file KeepAlive
Parent topic: Operations on queue managers