1

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.

JoshMc
  • 10,239
  • 2
  • 19
  • 38
  • Can you explain what you are trying to solve by setting `KeepAlive=YES`? Usually you can obtain the same results by proper configuration of the IBM MQ heart beat interval settings. The default settings on a `SVRCONN` channel will result in a MQ level TIMEOUT of 6 minutes, but it is easy to adjust this down to a much more reasonable value. If you can explain the problem you want to solve I can add some info in my answer on that setting as well. – JoshMc Nov 15 '18 at 00:17
  • Hi omniverseal, if my answer solved your problem please accept it. If you want to know more about how heart beat settings can help please explain the issue you want to solve with keepalive. – JoshMc Nov 22 '18 at 09:44
  • Hi omniversal, if you have any further questions let me know. If not and my answer solved your problem please accept it by clicking the gray check mark to the left of the answer. – JoshMc Mar 06 '19 at 19:23

1 Answers1

1

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.

JoshMc
  • 10,239
  • 2
  • 19
  • 38