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
