Using IBM MQ from Loadrunner Without the MQ Integration Feature

Posted by on December 14, 2010
Filed Under Performance Engineering | Comments Off

We have sometimes had a need to performence test a system by putting data onto an IBM MQ queue. Loadrunner has an option to integrate with IBM MQ, but an additional license is required. One solution we’ve used in the past is to write a custom Java class to access MQ, and use the Java integration feature of Loadrunner to call the Java class. This allows you to performance test MQ with Loadrunner without having to buy the MQ integration license. This technique should also work with other load generation tools, as long as they have the ability to call a Java class.

This approach requires familiarity with Java programming, and you need to have the MQ client Java libraries. I believe the Java libraries are part of the licensed client installation, but I don’t have a recent installation to reference. The example code I’ve included on this post is a little old, and not very robust. But the concept of using a Java class to test MQ from Loadrunner should still be valid.

The example code uses a static method to place a message on a queue. This allows it to be called without having to instantiate any objects from Loadrunner. You need to modify the script to fit your situation, i.e. change the server name, queue name, etc.  The test script you create in Loadrunner should be a Java test script.  You need to put the IBM MQ jar files and the jar file you created on the class path for the script.  You will need an “import” command in your script to import the Java class you created.  The example class has an initQueue method that you can call from the Loadrunner init method.  In the “action” section of the Loadrunner script, you need to call the static “runit” method and pass the message name you want to send.   I have put an example Loadrunner Java test script below.

The example Java class uses two different messages saved in text files on the hard drive.  It puts the one you requested onto the queue based on the parameter passed.  This allows you to change the messages without having to re-compile the class.  Don’t be confused by the names “SMS” and “Email” of the message types.  The application we were testing would send a user either an Email or and SMS message based on the data that was put on MQ.  The Java program itself does nothing but write the text that is in the file to MQ. 

 * LoadRunner Java script. (Build: 946)
 * Script Description:
public class Actions
 public int init() throws Throwable {
  return 0;
 }//end of init
 public int action() throws Throwable {
     lr.end_transaction("T01_mqSendSMSMessage", lr.AUTO);
     return 0;
 }//end of action
 public int end() throws Throwable {
  return 0;
 }//end of end

This post is intended to illustrate how it is possible to use Java integration to test with an IBM MQ installation.  It is NOT a turnkey or complete solution.  You need to have basic Java skills to be successful with it. 

The zip file below has the sample code, and a very basic build script.  It was coded on Windows, but should work on other platforms.  The zip file can be extracted anywhere you like, but the location of the message files is hard-coded, so you would need to change that in the Java class.  I have included the IBM jar files that we used so the class will compile, but they may not work for your situation, e.g. your communication protocol, Java version, or MQ version may be different.  You should use the jar files that came with your licensed IBM MQ client installation. 

Download: Loadrunner MQ Example

Some considerations:  the way the example class is written, it will read the input files every time it is called.  This could limit the Java class’s performance at very high loads.  Being called from a static method simplifies how to call the class from Loadrunner, but it is less efficient than other ways.   One possible way to make it more efficient would be to move some or all of the code into the Loadrunner Java test script itself.  I think there would be some limitations on capability, but that might work.  Another approach would be to put the code into a servlet container that you can call with an HTTP request, like Tomcat, or Jetty.  You would then write an HTTP test script in Loadrunner to call the servlet.  This should be much more efficient, but takes more work to set up.  IBM MQ has a JMS protocol interface as well.  Some use of that may work better in your situation.  The possibilities are endless.


Comments are closed.