Overriding connection properties: example with IBM MQ classes for JMS

This example shows how to override properties when we are using the IBM MQ classes for JMS.


The following code example shows how an application creates a ConnectionFactory programmatically:

JmsSampleApp.java
...
JmsFactoryFactory jmsff;
JmsConnectionFactory jmsConnFact;

jmsff = JmsFactoryFactory.getInstance(JmsConstants.WMQ_PROVIDER);
jmsConnFact = jmsff.createConnectionFactory();

jmsConnFact.setStringProperty(WMQConstants.WMQ_HOST_NAME,"127.0.0.1");
jmsConnFact.setIntProperty(WMQConstants.WMQ_PORT, 1414);
jmsConnFact.setStringProperty(WMQConstants.WMQ_QUEUE_MANAGER,"QM_V80");
jmsConnFact.setStringProperty(WMQConstants.WMQ_CHANNEL,"MY.CHANNEL");
jmsConnFact.setIntProperty(WMQConstants.WMQ_CONNECTION_MODE,
                           WMQConstants.WMQ_CM_CLIENT);
...

The ConnectionFactory is configured to connect to the queue manager QM_V80 using the CLIENT transport and channel MY.CHANNEL.

We can override the connection details by using a properties file, and force the application to connect to a different channel, by using the following procedure.


Procedure

  1. Create an IBM MQ classes for JMS configuration file that is called jms.config in the /userHome directory (where userHome is your home directory). Create this file with the following contents:
    jmscf.CHANNEL=MY.TLS.CHANNEL
    jmscf.SSLCIPHERSUITE=TLS_RSA_WITH_AES_128_CBC_SHA256
    
  2. Run the application, passing the following Java system properties into the Java runtime environment that the application is running in:
    -Dcom.ibm.msg.client.config.location=file:///userHome/jms.config    
    -Dcom.ibm.msg.client.jms.overrideConnectionFactory=true
    


Results

Carrying out this procedure overrides the ConnectionFactory that was created programmatically by the application, so that when the application creates a connection, it tries to connect by using the channel MY.TLS.CHANNEL and the cipher suite TLS_RSA_WITH_AES_128_CBC_SHA256.

Parent topic: Use IBM MQ connection property override


Related tasks