Programmatically Get IBM MQ Version for Both Client and Queue Manager

Recently, on both StackOverflow and mqseries.net, people have been asking about getting both the client and queue manager versions numbers for MQ.

It is pretty easy to get both the client and queue manager from the command line.

For the IBM MQ installation that is running the queue manager, you simply issue the following command:

dspmqver

To determine the MQ JAR file version number, you simply issue the following command:

java -jar com.ibm.mq.jar

or if you are using the com.ibm.mq.allclient.jar MQ JAR then do:

java -jar com.ibm.mq.allclient.jar

Now in theory, an MQ application should not care about what version of the queue manager it is connecting to or what MQ JAR files the application is using but sometimes it is nice to have all of the information in an application log file, so that you don’t have chase for the information after the fact.

IBM has done a terrible job making this kind of information available from the MQJavaLevel class file found in the found in com.ibm.mq.jar and com.ibm.mq.allclient.jar files.

A long time ago, I stumbled across the MQJavaLevel class and did a bunch of testing to figure how to programmatically get the version information from it and write it to the application’s log file.

Note: The following is undocumented and is from me beating MQ up a little bit. 🙂

The MQJavaLevel class has a method called queryValue. It takes an integer parameter between 0 to 4 and returns a String value.

  • 0 – will retrieve the MQ name i.e. IBM MQ classes for Java
  • 1 – will retrieve the MQ version i.e. 9.1.3.0
  • 2 – will retrieve the MQ level value i.e. p913-L190628
  • 3 – will retrieve the MQ build type i.e. Production
  • 4 – will retrieve the MQ JAR file location i.e. D:/Program Files/IBM/MQ/java/lib/com.ibm.mq.jar

The problem is, IBM never exposed the queryValue method. It is so weird. So, the only way around it is to create your own Java class that extends the MQJavaLevel class. You can have a look at the MQLevel class in the open source project called Universal File Mover (UFM).

It is a simple class:

package com.capitalware.ufm.mq;

import com.ibm.mq.MQJavaLevel;

public class MQLevel extends MQJavaLevel
{
   /**
    * The constructor
    */
   public MQLevel()
   {
      super();
   }

   /**
    * Get the IBM name for the MQ JAR class.
    * @return
    */
   public String getName()
   {
      return queryValue(0);
   }

   /**
    * Get the version of the MQ JAR class.
    * @return
    */
   public String getVersion()
   {
      return queryValue(1);
   }
}

Therefore, at the top/beginning of your Java and/or Java/JMS code, if you want to dump out the MQ name and version then do the following:

try
{
   ClassLoader classLoader = ClassLoader.getSystemClassLoader();
   Class.forName("com.ibm.mq.MQJavaLevel", false, classLoader);
   MQLevel mql = new MQLevel();
   System.out.println("MQ JAR Version = " + mql.getName()+" V"+mql.getVersion());
}
catch(ClassNotFoundException e)
{
   System.out.println("MQ is not in the CLASSPATH.");
}

The output will look like:

MQ JAR Version = IBM MQ classes for Java V9.1.3.0

The above code will work for both Java and Java/JMS applications.

Getting the queue manager’s version number is a little different. You cannot directly get the version number from the MQQueueManager class or JMS Connection class. But you can get the queue manager’s command level which is the first 3 digits of the version number. 9.1.3 vs 9.1.3.0

For a Java (non-JMS) programs, you can do the following:

MQQueueManager qMgr = new MQQueueManager(qMgrName);
System.out.println("MQ Command Level: " + qMgr.getCommandLevel());

For a Java/JMS programs, you can do the following:

Connection conn = cf.createConnection(userid, password);
JmsPropertyContext propertyContext = (JmsPropertyContext) conn;
System.out.println("MQ Command Level: " + propertyContext.getIntProperty(WMQConstants.WMQ_COMMAND_LEVEL));

If you truly want the queue manager’s version number then you will need to use MQ PCF command.

Here is how to do it:

MQQueueManager qMgr = new MQQueueManager(qMgrName);
PCFMessageAgent agent = new PCFMessageAgent(qMgr);
PCFMessage request = new PCFMessage(CMQCFC.MQCMD_INQUIRE_Q_MGR);
request.addParameter(CMQCFC.MQIACF_Q_MGR_ATTRS, new int [] { CMQC.MQCA_VERSION });
PCFMessage[] responses = agent.send(request);

for (PCFMessage response : responses)
{
   if (response.getCompCode() == CMQC.MQCC_OK)
   {
      System.out.println("MQ Version: " + response.getStringParameterValue(CMQC.MQCA_VERSION));
   }
}

Regards,
Roger Lacroix
Capitalware Inc.

This entry was posted in HPE NonStop, IBM i (OS/400), IBM MQ, IBM MQ Appliance, Java, JMS, Linux, macOS (Mac OS X), Open Source, PCF, Programming, Raspberry Pi, Unix, Windows.

Comments are closed.