IBM WebSphere MQ testing using LoadRunner
My first script for WebSphere MQ testing was written in Java as Java Vuser script. It was pretty simple since I was using just MQ JMS API. There is lots of examples howto connect to WebSphere in Java. Here is one http://hursleyonwmq.wordpress.com/2007/05/29/simplest-sample-applications-using-websphere-mq-jms/.
But howto test WebSphere MQ if you don’t have Java license in you LoadRunner?
There is a way to do that. LoadRunner API contains several JMS functions:
jms_receive_message_queue()
jms_send_message_queue()
jms_send_receive_message_queue()
jms_set_general_property()
jms_set_message_property()
First of all you need to have “Web Services” license to use them.
Here is what you need to do:
- Get details of your environment like: MQ server IP, port (probably 1414), Queue Manager name, Queue name and channel name.
Install IBM WebSphere MQ Client on machine where you have LoadRunner Controller (or LoadRunner Generator if you are using remote one). MQ Windows Client for WebSphere 6.0 can be downloaded here.
- Setup details of our WebSphere MQ server on the client. We will use JNDI to store connection details (host, port, etc…)
- Edit file C:\Program Files\IBM\WebSphere MQ\Java\bin\JMSAdmin.config and set
INITIAL_CONTEXT_FACTORY=com.sun.jndi.fscontext.RefFSContextFactory
PROVIDER_URL=file:/C:/JNDI
- Create new .scp file and put there your MQ server details. Here an example
DELETE QCF(QueueConnectionFactory)
DEFINE QCF(QueueConnectionFactory) QMGR(QUEUE_MANAGER) tran(client) chan(SYSTEM.ADMIN.SVRCONN) host(192.168.12.13) port(1414)
DISPLAY QCF(QueueConnectionFactory)
DEFINE Q(MY_QUEUE) QUEUE(MY_QUEUE) QMGR(QUEUE_MANAGER)
DISPLAY Q(MY_QUEUE)
end
- Last step for MQ Client is to generate .bindings file (placed automatically in C:/JNDI) with JMSAdmin tool from C:\Program Files\IBM\WebSphere MQ\Java\bin directory. Assuming that your .scp file is named My_qm.scp, use this command:
JMSAdmin < My_qm.scp
Now in LoadRunner:
- Create new Web Services script
- Open Run-Time settings (F4) and go to JMS/Advanced
- Change JNDI initial context factory to “com.sun.jndi.fscontext.RefFSContextFactory”
- Change JNDI provider URL to “file:/C:/JNDI”
- Change JMS connection factory to “QueueConnectionFactory” and click OK
Use this sample code to send and receive a message from IBM WebSphere MQ:
//setting JMS message property JmsMessageID
jms_set_message_property("JMSMessageID","JMSMessageID", "12345");
//sending message
jms_send_message_queue("Sending message","My cool message", "MY_QUEUE");
//receiving message
jms_receive_message_queue("Receiving message", "MY_QUEUE");
//displaying message
lr_message(lr_eval_string("{JMS_message}"));
Received message is saved in “JMS_message” parameter automatically by LoadRunner.
Done. Smart and simple

captcha test
bots go home
The last step you mentioned ,do we have to type that “JMSAdmin < My_qm.scp” in the JMSadmil.bat file?
“Last step for MQ Client is to generate .bindings file (placed automatically in C:/JNDI) with JMSAdmin tool from C:\Program Files\IBM\WebSphere MQ\Java\bin directory. Assuming that your .scp file is named My_qm.scp, use this command:
JMSAdmin < My_qm.scp”
No, you don’t need to edit JMSAdmin.bat (and you shouldn’t). You should only run it with correct arguments. “JMSAdmin < My_qm.scp” is a command that you should run in Windows’s cmd command shell.
Thanks waldeMar.I will try this approach ,since we have a crucial need to test websphere MQ.
I have done step 1 edit and step 2-create a .scp file with the above details copy pasted and put the file into >JAVA>bin
when i tried the step 3-command in dos prompt i get the message \’Java is not recognized as internal or external command,operbale program or batch file\’.what do i do?
It looks like you don’t have Java installed or you don’t have %JAVA_HOME/bin in your $PATH environment variable.
You can download Java here http://java.sun.com/javase/downloads/index.jsp
i have installed java and then reran that command and i get the following message
5724-H72, 5655-L82, 5724-L26 (c) Copyright IBM Corp. 2002,2005. All Rights Reser
ved.
Starting Websphere MQ classes for Java(tm) Message Service Administration
JNDI initialization failed, please check your JNDI settings and service.
For additional information on the cause of this problem run with the -v argument
C:\\Program Files\\IBM\\WebSphere MQ\\Java\\bin>
This is the more detailed error message i am getting”
5724-H72, 5655-L82, 5724-L26 (c) Copyright IBM Corp. 2002,2005. All Rights Reser
ved.
Starting Websphere MQ classes for Java(tm) Message Service Administration
Initializing JNDI Context…
INITIAL_CONTEXT_FACTORY: com.sun.jndi.fscontext.RefFSContextFactory
PROVIDER_URL: file:/C:/JNDI
JNDI initialization failed, please check your JNDI settings and service.
For additional information on the cause of this problem run with the -v argument
Error: javax.naming.NameNotFoundException; remaining name ‘C:\JNDI’
C:\Program Files\IBM\WebSphere MQ\Java\bin>
Do you have C:/JNDI directory on the disk?
No i donot
OK, so create that directory. JMSAdmin will create .bindings file there.
I just created that folder on the c drive and reran the command and here is what i got.
5724-H72, 5655-L82, 5724-L26 (c) Copyright IBM Corp. 2002,2005. All Rights Reser
ved.
Starting Websphere MQ classes for Java(tm) Message Service Administration
Initializing JNDI Context…
INITIAL_CONTEXT_FACTORY: com.sun.jndi.fscontext.RefFSContextFactory
PROVIDER_URL: file:/C:/JNDI
Done.
Welcome to the Admin Tool’s command-line interface
InitCtx> Unknown command: {\RTF1\ANSI\ANSICPG1252\DEFF0\DEFLANG1033{\FONTTBL{\F0
\FROMAN\FCHARSET0
InitCtx> Unknown command: {\*\GENERATOR
InitCtx> Unknown command: \PARD\F1\FS20\PAR
InitCtx> Unknown command: }
InitCtx>
InitCtx>
Also i didn’t do the initial step u mentioned”
Setup details of our WebSphere MQ server on the client. We will use JNDI to store connection details (host, port, etc…)
”
DO i need to do that ,if yes how.
Yes, you should follow the steps (all). In other case I can’t help you.
ok .how do i do the following step”
Setup details of our WebSphere MQ server on the client. We will use JNDI to store connection details (host, port, etc…)
”
I have all the details of the MQ server
You have to edit JMSAdmin.config file.
if you are talking abt this step”
INITIAL_CONTEXT_FACTORY=com.sun.jndi.fscontext.RefFSContextFactory
PROVIDER_URL=file:/C:/JNDI
I already did that
Waldek,
Have you ever tried doing automated failover tests (i.e. testing connectivity problems) when working with WebSphere MQ broker? If so, have you observed any issues with CPU utilization after WebSphere MQ Java client reconnects to the broker?
Thanks,
Anonymous SOA enthusiast from BUMA, Krakow
I haven’t tried that.
Hi waldemar,
I am getting the following errors in Lr when i run this script:
vuser_init.c(5): Error: Failed to set property name JMSMessageID value 12345 due to the following exception : javax.naming.NoInitialContextException: Cannot instantiate class: com.sun.jndi.fscontext.RefFSContextFactory [Root exception is java.lang.ClassNotFoundException: com.sun.jndi.fscontext.RefFSContextFactory]
javax.naming.NoInitialContextException: Cannot instantiate class: com.sun.jndi.fscontext.RefFSContextFactory [Root exception is java.lang.ClassNotFoundException: com.sun.jndi.fscontext.RefFSContextFactory]
at javax.naming.spi.NamingManager.getInitialContext(NamingManager.java:657)
at javax.naming.InitialContext.getDefaultInitCtx(InitialContext.java:247)
at javax.naming.InitialContext.init(InitialContext.java:223)
at javax.naming.InitialContext.<init>(InitialContext.java:197)
at com.mercury.ws.jms.ConnectionManagerImpl.initialize(Unknown Source)
at com.mercury.ws.jms.JMSSupportImpl.initialize(Unknown Source)
at com.mercury.ws.jms.JMSBridge.init_jms(Unknown Source)
Caused by: java.lang.ClassNotFoundException: com.sun.jndi.fscontext.RefFSContextFactory
at java.net.URLClassLoader$1.run(URLClassLoader.java:200)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:188)
at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:268)
at java.lang.ClassLoader.loadClass(ClassLoader.java:251)
at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:319)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:242)
at com.sun.naming.internal.VersionHelper12.loadClass(VersionHelper12.java:42)
at javax.naming.spi.NamingManager.getInitialContext(NamingManager.java:654)
… 6 more
vuser_init.c(5): Error: JMS call execution failed
Abort was called from an action.
ClassNotFoundException: com.sun.jndi.fscontext.RefFSContextFactory looks for me like LR is not able to find jar files.
Do you have MQ client installed?
In Run-Time settings -> Java, there should be something line classpath. Try to add there paths to jars installed with MQ Client. Example classpath: “C:/Program Files/…/mq.jar; C:/Program Files/…/jms.jar;”
yes i do have the IBM websphere MQ V6 installed.also when i did the binding,i got these in the cmd prompt,Could it be something here itself.
\"
5724-H72, 5655-L82, 5724-L26 (c) Copyright IBM Corp. 2002,2005. All Rights
ved.
Starting Websphere MQ classes for Java(tm) Message Service Administration
Initializing JNDI Context…
INITIAL_CONTEXT_FACTORY: com.sun.jndi.fscontext.RefFSContextFactory
PROVIDER_URL: file://C:/JNDI
Done.
Welcome to the Admin Tool\’s command-line interface
InitCtx> Binding non-administerable or not found
javax.naming.NameNotFoundException: QueueConnectionFactory
InitCtx>
InitCtx>
MSGRETENTION(YES)
QMANAGER(test)
TARGCLIENTMATCHING(YES)
SSLRESETCOUNT(0)
TEMPMODEL(SYSTEM.DEFAULT.MODEL.QUEUE)
USECONNPOOLING(YES)
POLLINGINT(5000)
RESCANINT(5000)
LOCALADDRESS()
TRANSPORT(CLIENT)
HOSTNAME(L2512156)
TEMPQPREFIX()
CHANNEL(SYSTEM.ADMIN.SVRCONN)
SYNCPOINTALLGETS(NO)
CCSID(819)
CONNOPT(STANDARD)
Before creating new connection factory, old one is deleted so if you don’t have it, you will see something like this.
i have tried adding the classpath to the ibm websphere mq server jar file:eg to jms.jar,but still the same issue is happenning on running the scrip.I wasnot able to locate the mq.jar in the installation folders.
For interested I have set up connection from Load Runner to IBM WebSphere MQ.
I have used as initial context factory class com.ibm.mq.jms.context.WMQInitialContextFactory and as url provider localhost:1414/SYSTEM.DEF.SVRCONN.
Here you have description of the class http://www.ibm.com/developerworks/websphere/techjournal/0502_woolf/0502_woolf.html
So what is different to Waldemar solution is:
1) We have to download libraries from IBM web site:
– com.ibm.mq.pcf-6.1.jar
– connector.jar
– dhbcore.jar
– mqcontext.jar
and set up them in LoadRunner Classpath.
My Classpath looks in Load Runner :
%CLASSPATH%;c:\work\loadrunner_for_jms\LIB\dhbcore.jar;c:\work\loadrunner_for_jms\LIB\mqcontext.jar;c:\work\loadrunner_for_jms\LIB\connector.jar;c:\work\loadrunner_for_jms\LIB\com.ibm.mq.pcf-6.1.jar;c:\Program Files\IBM\WebSphere MQ\Java\lib\jms.jar;c:\Program Files\IBM\WebSphere MQ\Java\lib\jndi.jar;c:\Program Files\IBM\WebSphere MQ\Java\lib\com.ibm.mq.jar;c:\Program Files\IBM\WebSphere MQ\Java\lib\com.ibm.mqjms.jar
2) In JMSAdmin.config we need to set up:
INITIAL_CONTEXT_FACTORY=com.ibm.mq.jms.context.WMQInitialContextFactory
PROVIDER_URL=localhost:1414/SYSTEM.DEF.SVRCONN
3) In Load Runner configuration we have to set up:
JNDI initial context factory: com.ibm.mq.jms.context.WMQInitialContextFactory
JNDI provider URL: localhost:1414/SYSTEM.DEF.SVRCONN
JNDI connection factory: name from .scp file
4) Add classpath to JMSAdmin.bat:
-cp “%CLASSPATH%;c:\work\loadrunner_for_jms\LIB\com.ibm.mq.jar;c:\work\loadrunner_for_jms\LIB\com.ibm.mqjms.jar;c:\work\loadrunner_for_jms\LIB\dhbcore.jar;c:\work\loadrunner_for_jms\LIB\mqcontext.jar;c:\work\loadrunner_for_jms\LIB\jms.jar;c:\work\loadrunner_for_jms\LIB\connector.jar;c:\work\loadrunner_for_jms\LIB\com.ibm.mq.pcf-6.1.jar”
and run JMSAdmin.bat.
The advantage of the solution is that you can test MQ from other PC station with LR without “.bindings” file. Watch out on ip of the PC with the MQ. If you set up localhost – second PC with LR will try to connect to localhost on their computer. To configure two PC use raw IP address.
Waldemar,
I have in my LR script your code point to my local Queue.
RTS:
JVM Home:%JDK_HOME%
Class Path:c:\Program Files\IBM\WebSphere MQ\Java\lib\jms.jar;c:\Program Files\IBM\WebSphere MQ\Java\lib\com.ibm.mq.jar;c:\Program Files\IBM\WebSphere MQ\Java\lib\com.ibm.mqjms.jar
and when i run the script get the following error:(Can you please help me out)
Vuser directory: “C:\Documents and Settings\sjose\Desktop\mqJMS”
Vuser output directory: “C:\Documents and Settings\sjose\Desktop\mqJMS\”
LOCAL start date/time: 2009-08-11 12:25:14
vuser_init.c(5): JMS call “JMSMessageID” started
vuser_init.c(5): JMS call was successful
vuser_init.c(8): JMS call “Sending message” started
vuser_init.c(8): Error: Failed to send message My cool message to A due to the following exception : javax.jms.JMSException: MQJMS2005: failed to create MQQueueManager for ‘10.26.5.79:test’
javax.jms.JMSException: MQJMS2005: failed to create MQQueueManager for ‘10.26.5.79:test’
at com.ibm.mq.jms.services.ConfigEnvironment.newException(ConfigEnvironment.java:586)
at com.ibm.mq.jms.MQConnection.createQM(MQConnection.java:2110)
at com.ibm.mq.jms.MQConnection.createQMNonXA(MQConnection.java:1532)
at com.ibm.mq.jms.MQQueueConnection.(MQQueueConnection.java:150)
at com.ibm.mq.jms.MQQueueConnectionFactory.createQueueConnection(MQQueueConnectionFactory.java:185)
at com.ibm.mq.jms.MQQueueConnectionFactory.createQueueConnection(MQQueueConnectionFactory.java:112)
at com.mercury.ws.jms.ConnectionManagerImpl.getConnection(Unknown Source)
at com.mercury.ws.jms.ConnectionManagerImpl.getQueueConnection(Unknown Source)
at com.mercury.ws.jms.JMSSupportImpl.sendMessageQueue(Unknown Source)
at com.mercury.ws.jms.JMSBridge.send_message_queue(Unknown Source)
vuser_init.c(8): Error: JMS call execution failed
Abort was called from an action.
It is working perfectly now,the issue was with the channel,i had put in the wrong channel name.I tried connecting to local mq server as well as remote one,works fine,Thanks for the great info.
Question:With your(waldemars and anonymous)suggestions.From any LR Generator machine,we can only test 1 partcular MQ server (Hostname/queuemanager/channel/queue).
what if in that 1 MQ server there are other queue managers with queues,if we want to test all of them ,we need to have separate LR machines(with separate bindings).Correct?