Using LoadRunner Java Vusers with WebLogic JMS Queues/Topics
2 March, 2008 – 10:07 amThe following scripts are examples on how to generate load for the BEA WebLogic implementation of JMS. Specifically I demonstrate how to place messages on a queue and how to publish messages to a topic using a Java Vuser within LoadRunner.
There are a few pre-requisites to get this all working.
BEA WebLogic JMS supports the Sun JMS Specification which implements the standard JMS APIs. So in order for your code to work, you must have the latest JMS package (jms.jar) which I sourced from the Sun SDK for enterprise messaging. Because I had so much difficulty getting my hands on this, I’ll host it here for the time being if you’re interested in running your own demo.
You will also need a copy of the WebLogic package (weblogic.jar) which is typically found in the lib directory of your WebLogic server. The code demonstrated in this blog uses WebLogic 9.2.x
You will need to tell your Java Vuser where to get these libraries, which is done by modifying the run-time settings (F4) in VuGen.

Also, if you’ve never created a Java Vuser before, then make sure your load generators have a copy of the Sun JDK; I used 1.5.0_14 …
The following code examples have been written for a Point-To-Point (writing messages to a queue) and Pub/Sub (publishing messages to a topic) scenario. You can use either depending on your requirements.
I have also parametized some values, with original values commented so you can see what they look like. I’ve also thrown in a couple of other LoadRunner API specific calls, to demonstrate some handy methods for logging and transactions.
For now, I only need to load specific queues or topics, with no requirement to simulate a subscriber/consumer for these modules, although if you needed to, the following code should give you enough of a head start coupled with examples provided by BEA. This article is also a great example of achieving a similar purpose for a TIBCO implementation using SOAP over JMS. Nice one Stuart
JMSLoadQueuePTP - Download Script
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 | /* * LoadRunner Java script. (Build: 873) * * Script Description: This examples shows how to establish a connection and * send messages to a JMS queue. It requires the jms.jar and weblogic.jar * packages to be available in your run-time settings classpath. * * Author: tim.koopmans@90kts.com * */ import lrapi.lr; import java.util.Hashtable; import javax.jms.*; import javax.naming.Context; import javax.naming.InitialContext; import javax.naming.NamingException; public class Actions { // Define public paramse public final static String JNDI_FACTORY = "weblogic.jndi.WLInitialContextFactory"; public String JMS_FACTORY; public String QUEUE; public String URL; // Define private params private QueueConnectionFactory qconFactory; private QueueConnection qcon; private QueueSession qsession; private QueueSender qsender; private Queue queue; private TextMessage msg; public int init() throws NamingException, JMSException { // Parameters JMS_FACTORY = "<JMS_FACTORY>"; // e.g. weblogic.sandbox.connectionFactory QUEUE = "<QUEUE>"; // e.g. weblogic.sandbox.queue URL = "<URL>"; // e.g. t3://192.168.249.128:7001 //lr.message( "DEBUG: URL " + URL ); // Setup initial context and JNDI factory Hashtable<String,String> env = new Hashtable<String,String>(); env.put(Context.INITIAL_CONTEXT_FACTORY, JNDI_FACTORY); env.put(Context.PROVIDER_URL, URL); InitialContext ctx = new InitialContext(env); // Establish connection to JMS queue lr.start_transaction("connect_to_server"); qconFactory = (QueueConnectionFactory) ctx.lookup(JMS_FACTORY); qcon = qconFactory.createQueueConnection(); qsession = qcon.createQueueSession(false, Session.AUTO_ACKNOWLEDGE); queue = (Queue) ctx.lookup(QUEUE); qsender = qsession.createSender(queue); qcon.start(); lr.end_transaction("connect_to_server", lr.AUTO); return 0; } //end of init public int action() throws JMSException { // Typically you would parametize the following string String FORMATTED_MESSAGE = "<?xml version=\"1.0\"?>\n"+ "<PARTS>\n"+ " <TITLE>Computer Parts</TITLE>\n"+ " <PART>\n"+ " <ITEM>Motherboard</ITEM>\n"+ " <MANUFACTURER>ASUS</MANUFACTURER>\n"+ " <MODEL>P3B-F</MODEL>\n"+ " <COST> 123.00</COST>\n"+ " </PART>\n"+ " <PART>\n"+ "</PARTS>\n"; // Create a message object msg = qsession.createTextMessage(); msg.setText(FORMATTED_MESSAGE); // Send the message object lr.start_transaction("send_message"); qsender.send(msg); lr.end_transaction("send_message", lr.AUTO); return 0; } //end of action public int end() throws JMSException { // Close all JMS objects qsender.close(); qsession.close(); qcon.close(); return 0; } //end of end } |
JMSLoadTopicPUB - Download Script
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 | /* * LoadRunner Java script. (Build: 873) * * Script Description: This examples shows how to establish a connection and * send messages to a JMS topic. It requires the jms.jar and weblogic.jar * packages to be available in your run-time settings classpath. * * Author: tim.koopmans@90kts.com * */ import lrapi.lr; import java.util.Hashtable; import javax.jms.*; import javax.naming.Context; import javax.naming.InitialContext; import javax.naming.NamingException; import javax.rmi.PortableRemoteObject; public class Actions { // Define public params, typically you would parametize these public final static String JNDI_FACTORY = "weblogic.jndi.WLInitialContextFactory"; public String JMS_FACTORY; public String TOPIC; public String URL; // Define private params private TopicConnectionFactory tconFactory; private TopicConnection tcon; private TopicSession tsession; private TopicPublisher tpublisher; private Topic topic; private TextMessage msg; public int init() throws NamingException, JMSException { // Parameters JMS_FACTORY = "<JMS_FACTORY>";// e.g. weblogic.sandbox.connectionFactory TOPIC = "<TOPIC>"; // e.g. weblogic.sandbox.topic URL = "<URL>"; // e.g. t3://192.168.249.128:7001 //lr.message( "DEBUG: URL " + URL ); // Setup initial context and JNDI factory Hashtable<String,String> env = new Hashtable<String,String>(); env.put(Context.INITIAL_CONTEXT_FACTORY, JNDI_FACTORY); env.put(Context.PROVIDER_URL, URL); env.put("weblogic.jndi.createIntermediateContexts", "true"); InitialContext ctx = new InitialContext(env); // Establish connection to JMS topic as PUB lr.start_transaction("connect_to_server"); tconFactory = (TopicConnectionFactory) PortableRemoteObject.narrow(ctx.lookup(JMS_FACTORY), TopicConnectionFactory.class); tcon = tconFactory.createTopicConnection(); tsession = tcon.createTopicSession(false, Session.AUTO_ACKNOWLEDGE); topic = (Topic) PortableRemoteObject.narrow(ctx.lookup(TOPIC), Topic.class); tpublisher = tsession.createPublisher(topic); tcon.start(); lr.end_transaction("connect_to_server", lr.AUTO); return 0; } //end of init public int action() throws JMSException { // Typically you would parametize the following string String FORMATTED_MESSAGE = "<?xml version=\"1.0\"?>\n"+ "<PARTS>\n"+ " <TITLE>Computer Parts</TITLE>\n"+ " <PART>\n"+ " <ITEM>Motherboard</ITEM>\n"+ " <MANUFACTURER>ASUS</MANUFACTURER>\n"+ " <MODEL>P3B-F</MODEL>\n"+ " <COST> 123.00</COST>\n"+ " </PART>\n"+ " <PART>\n"+ "</PARTS>\n"; // Create a message object msg = tsession.createTextMessage(); msg.setText(FORMATTED_MESSAGE); // Send the message object lr.start_transaction("send_message"); tpublisher.publish(msg); lr.end_transaction("send_message", lr.AUTO); return 0; } //end of action public int end() throws JMSException { // Close all JMS objects tpublisher.close(); tsession.close(); tcon.close(); return 0; } //end of end } |









8 Responses to “Using LoadRunner Java Vusers with WebLogic JMS Queues/Topics”
Thank you for sharing your experience!
By Dmitry Motevich on Mar 2, 2008
Don’t forget!
Note: If you are making calls to JNDI extensions within your script, you may encounter problems trying to run your Vusers as threads. This happens because JNDI requires each thread to have its own context class loader. In order to run as threads, instruct each Vuser to run with its own context class loader, by adding the following line to the beginning of the init section:
DummyClassLoader.setContextClassLoader();
By Tim on Apr 16, 2008
Hi!
I couldn’t find the weblogic.jar. Could you please post a link to it?
Thanks
By SER on May 16, 2008
weblogic.jar is available from your Weblogic installation. I can’t post it here for both commercial and size reasons.
Regards,
Tim
By Tim on May 30, 2008
By shanthi on Jun 20, 2008
i have tried the topics example given above sun’s mq server. everything compiles and runs from loadrunner side telling that the messsages are sent to the server but the JMS server does not report of any messages reaching it. i have tried another example with the same configuration using jmeter and that works fine.
By avinash on Aug 16, 2008
Awesome ! it worked really well . Thanks TKS !
I am also looking for some monitors which will allow me to monitor the JMS queues that is sent and received from WL using LR .I am thinking about sitescope but not sure if it supports JMS.
By Senthil on Sep 22, 2008
No problems. For JMS queue information I would recommend using JMX. Weblogic has its own implementation. For tips on how to do this, just search this blog for JMX.
Cheers
Tim
By Tim on Sep 22, 2008