Reputation: 11
I am looking for a way to programmatically set client attributes inside an IBM MQ Java client application. I do realise IBM provides a way of configuring MQ Clients using a mqclient.ini
file, however due to the nature of deployment and distribution of the application I'm working on it is not possible to use such a file. Hence, I want to set a stanza attribute that would normally be defined in the ini file, inside the connetion configuration block of my code.
Furthermore, I am aware that certain properties can be set as environment variables or Java command line arguments, but that would not be a viable workaround due to the same reasons mentioned above.
In particular I'm interested in the setting the KeepAlive
attribute in the TCP stanza to YES.
So far I have attempted the following ways of achieving that using an MQQueueConnectionFactory
:
connectionFactory.setStringProperty("KeepAlive", "YES");
connectionFactory.setStringProperty("com.ibm.mq.cfg.TCP.KeepAlive", "YES");
connectionFactory.setBooleanProperty("KeepAlive", true);
connectionFactory.setBooleanProperty("com.ibm.mq.cfg.TCP.KeepAlive", true);
However, none of those have had any effect.
For the record I am using IBM MQ classes for JMS version 8.
Upvotes: 1
Views: 1278
Reputation: 10652
You can use Java system properties for this purpose.
The following Java system property will be read by IBM MQ classes for JMS to tell it to use TCP KeepAlive:
com.ibm.mq.cfg.TCP.KeepAlive=YES
To set this programmatically just use System.setProperty
method for example:
System.setProperty("com.ibm.mq.cfg.TCP.KeepAlive","YES");
Oracle documents the setProperty
method in the Class System:
setProperty
public static String setProperty(String key, String value)
Sets the system property indicated by the specified key.
IBM "loosly" documents specifying a mqclient.ini setting as a system property in the IBM MQ v8 Knowledge center page The IBM MQ classes for JMS configuration file:
Overriding properties specified in an IBM MQ MQI client configuration file
An IBM MQ MQI client configuration file can also specify properties that are used to configure IBM MQ classes for JMS. 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, you can override any attribute in a IBM MQ MQI client configuration file by specifying it as a property in a IBM MQ classes for JMS configuration file. To override an attribute in a IBM MQ MQI client configuration file, use an entry with the following format in the IBM MQ classes for JMS configuration file:
com.ibm.mq.cfg. stanza. propName = propValueCopy
The variables in the entry have the following meanings:
stanza The name of the stanza in the IBM MQ MQI client configuration file that contains the attribute
propName The name of the attribute as specified in the IBM MQ MQI client configuration file
propValue The value of the property that overrides the value of the attribute specified in the IBM MQ MQI client configuration file
Alternatively, you can override an attribute in an IBM MQ MQI client configuration file by specifying the property as a system property on the java command. Use the preceding format to specify the property as a system property.
Upvotes: 1