The wheel has turned full circle and I’m back in MQ land… So here is a a simple Java vuser harness which you can use in LoadRunner to put or get messages from Websphere MQ. This version doesn’t require any JNDI bindings (or access to JMS). Instead it just uses a standard server connection channel over TCP to get and put messages.
You will need to get the following jars from your Websphere MQ installation:
1. com.ibm.mq.jar
2. connector.jar
3. jta.jar
Make sure you include them in your run-time settings (F4) for your script:

PUT example
/* * LoadRunner Java script. (Build: 946) * * Script Description: simple test harness to PUT messages on a MQ queue * Author: Tim.Koopmans@90kts.com */ import lrapi.lr; import java.io.*; import java.util.*; import com.ibm.mq.*; public class Actions { private MQQueueManager myQueueManager; private MQPutMessageOptions myPutMsgOptions; private MQQueue myQueue; public int init() throws Throwable { try { MQEnvironment.hostname = "192.168.145.131"; MQEnvironment.properties.put(MQC.TRANSPORT_PROPERTY,MQC.TRANSPORT_MQSERIES_CLIENT); MQEnvironment.channel = "S_koops_5a7610a22"; MQEnvironment.port = 1414; MQEnvironment.CCSID = 437; myQueueManager = new MQQueueManager("QM_koops_5a7610a22"); int openOptions = MQC.MQOO_OUTPUT | MQC.MQOO_INQUIRE | MQC.MQOO_FAIL_IF_QUIESCING; myQueue = myQueueManager.accessQueue("default", openOptions, null, null, null); myPutMsgOptions = new MQPutMessageOptions(); myPutMsgOptions.options = MQC.MQPMO_NONE; } catch (Exception e) { System.out.println(e); } return 0; }//end of init public int action() throws Throwable { try { MQMessage myPutMessage = new MQMessage(); myPutMessage.clearMessage(); myPutMessage.persistence = MQC.MQPER_PERSISTENT; //myPutMessage.persistence = MQC.MQPER_NOT_PERSISTENT; myPutMessage.correlationId = MQC.MQCI_NONE; myPutMessage.messageId = MQC.MQMI_NONE; myPutMessage.writeString("<xml><data>foobar</data></xml>"); myQueue.put(myPutMessage, myPutMsgOptions); } catch (MQException e) { System.out.println(e); } return 0; }//end of action public int end() throws Throwable { try { myQueue.close(); myQueueManager.disconnect(); } catch (Exception e ) { System.out.println(e); } return 0; }//end of end }
GET example
I’ve included a private method which decodes the hex string (for the msgID) into ascii. You can also get creative here. In previous test efforts I’ve embedded a date time string in the user data of the request message, then extracted and got the difference from the MQMD header on the reply queue. In other words, elapsed time between request and response. I’m keeping it simple for the example though …
/* * LoadRunner Java script. (Build: 946) * * Script Description: simple test harness to GET messages on a MQ queue * Author: Tim.Koopmans@90kts.com */ import lrapi.lr; import java.io.*; import java.util.*; import com.ibm.mq.*; public class Actions { private MQQueueManager myQueueManager; private MQPutMessageOptions myPutMsgOptions; private MQQueue myQueue; public int init() throws Throwable { try { MQEnvironment.hostname = "192.168.145.131"; MQEnvironment.properties.put(MQC.TRANSPORT_PROPERTY,MQC.TRANSPORT_MQSERIES_CLIENT); MQEnvironment.channel = "S_koops_5a7610a22"; MQEnvironment.port = 1414; MQEnvironment.CCSID = 437; myQueueManager = new MQQueueManager("QM_koops_5a7610a22"); int openOptions = MQC.MQOO_INPUT_SHARED | MQC.MQOO_INQUIRE | MQC.MQOO_FAIL_IF_QUIESCING; myQueue = myQueueManager.accessQueue("default", openOptions); } catch (Exception e) { System.out.println(e); } return 0; }//end of init public int action() throws Throwable { try { MQMessage myGetMessage = new MQMessage(); myQueue.get(myGetMessage); System.out.println("MSG ID: \t"+dumpHexId(myGetMessage.messageId)); System.out.println("CORREL ID: \t"+dumpHexId(myGetMessage.correlationId)); System.out.println("MSG LENGTH:\t"+myGetMessage.getMessageLength()+" bytes"); System.out.println("MSG CONTENT: "+myGetMessage.readLine()); } catch (MQException e) { System.out.println(e); } return 0; }//end of action public int end() throws Throwable { try { myQueue.close(); myQueueManager.disconnect(); } catch (Exception e ) { System.out.println(e); } return 0; }//end of end private static String dumpHexId(byte[] myId) { String hexAscii = ""; for (int i=0; i < myId.length;i++) { char b = (char)(myId[i] & 0xFF); if (b < 0x10) { hexAscii = hexAscii + "0"; } hexAscii = hexAscii + (String)(Integer.toHexString(b)).toUpperCase(); } return hexAscii; }//end of dumpHexId }

I am doing similar type of script in LR and it complies but do not execute.. getting this error.
16/11/2008 15:46:32 Error (-104998): RTC Client Error: Failed to get PT instance of RTC Client.
Just wondering if you got this.. Am i missing something really simple?
please let me know if you have any ideas
Are there any errors prior to this? Anymore error information?
Nothing. I did get compile errors like this
Error: Compilation process failed.[MsgId: MERR-22997]
Warning: Extension java_int.dll reports error -1 on call to function ExtPerProcessInitialize[MsgId: MWAR-10485]
Error: Thread Context: Call to service of the driver failed, reason – thread context wasn’t initialized on this thread.[MsgId: MERR-10176]
but once compilation error was gone, I got this sinlge error in mrdv.log file. Vugen output do not show anything.
you have mentioned the classpath for jar file.. is it mandatory to have jar files in Classes directory under Mercury/LoadRuner
It is not mandatory to have jar files in the the mercury classes directory. They can be anywhere on your system, provided you point to them in your runtime settings.
The fact that it’s compiling does not indicate a classpath problem. I would be more suspect of the versions of jars you are using against your target MQ installation. The example code given above was developed on MQ version 7.0.
Are you able to step through your code (F10) to see which line of code it is failing on? Vugen should be giving you more information than what you’ve reported…
This worked like a charm.
Thankyou
I have a requirement to pass an xml input to the queue and the message response will be in X12 format. To set the connection which are aal information about the server needed like passing parameters in above code?
The JAR files need to be accessible to Loadrunner when it compiles. By specifying the location of the Classpath files in the runtim,e settings, youb are telling Loadrunner where to find the Classpath files so that compilation will work.
While this may seem straightforward and obvious, The way Loadrunner interacts wiuth the compiler means that it detects the names of the classpath files, but cannot work out where they are.
No problem, we can change the path statement on the environment variables for the machine running vugen.
Again, no luck, Loadrunner wont compile. The real awnser is too pysically put the jar files inside the Loadrunner directory within proigram files and adjust the classpath statements accordingly.
For more information, see http://www.testingperformance.org
At this point your script will compile and any other errors after this are down to real coding issues.
I have tried the PUT example script, modified the MQ parameters and compile it using Loadrunner… It shows no errors.
But when I run it, it stops on the MQEnvironment.channel line and got this Eror: System.err: MQJE001: An MQException occurred: Completion Code 2, Reason 2009
MQJE016: MQ queue manager closed channel immediately during connect
Closure reason = 2009
Could you help me in debugging this error?
Also, does the “default” in myQueueManager.accessQueue(“default”, openOptions); the MQ Queue name?
Thanks.
hi,
I have to work for the similar application.
My application takes the mq messages and send it to the Oracle data base.
We have to send XML/swift message through MQ and insert the data in to the DB to check the performance of the db and volume testing too.
Please help me ..
Thanks,
Satya
I used the above code to feed MQ messages, see the following error
.java:16: Class MQQueueManager not found in type declaration.
private MQQueueManager myQueueManager;
^
java:17: Class MQPutMessageOptions not found in type declaration.
private MQPutMessageOptions myPutMsgOptions;
^
java:18: Class MQQueue not found in type declaration.
private MQQueue myQueue;
^
Please help