The 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 } |

Thank you for sharing your experience!
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();
Hi!
I couldn’t find the weblogic.jar. Could you please post a link to it?
Thanks
weblogic.jar is available from your Weblogic installation. I can’t post it here for both commercial and size reasons.
Regards,
Tim
Error: System.err: javax.naming.NameNotFoundException: Unable to resolve ‘BTQueueConnectionFactory’ Resolved [Root exception is javax.naming.NameNotFoundException: Unable to resolve 'BTQueueConnectionFactory' Resolved ]; remaining name ‘BTQueueConnectionFactory’ Error
System.err: at weblogic.rjvm.BasicOutboundRequest.sendReceive(BasicOutboundRequest.java:108) Error
System.err: at weblogic.rmi.cluster.ReplicaAwareRemoteRef.invoke(ReplicaAwareRemoteRef.java:290) Error
System.err: at weblogic.rmi.cluster.ReplicaAwareRemoteRef.invoke(ReplicaAwareRemoteRef.java:248) Error
System.err: at weblogic.jndi.internal.ServerNamingNode_815_WLStub.lookup(Unknown Source) Error
System.err: at weblogic.jndi.internal.WLContextImpl.lookup(WLContextImpl.java:375) Error
System.err: at weblogic.jndi.internal.WLContextImpl.lookup(WLContextImpl.java:363) Error
System.err: at javax.naming.InitialContext.lookup(InitialContext.java:351) Error
System.err: at Actions.init(Actions.java:52) Error
Error: System.err: Caused by: javax.naming.NameNotFoundException: Unable to resolve ‘BTQueueConnectionFactory’ Resolved Error
Error: System.err: at weblogic.jndi.internal.BasicNamingNode.newNameNotFoundException(BasicNamingNode.java:924) Error
System.err: at weblogic.jndi.internal.BasicNamingNode.lookupHere(BasicNamingNode.java:230) Error
System.err: at weblogic.jndi.internal.ServerNamingNode.lookupHere(ServerNamingNode.java:154) Error
System.err: at weblogic.jndi.internal.BasicNamingNode.lookup(BasicNamingNode.java:188) Error
System.err: at weblogic.jndi.internal.RootNamingNode_WLSkel.invoke(Unknown Source) Error
System.err: at weblogic.rmi.internal.BasicServerRef.invoke(BasicServerRef.java:492) Error
System.err: at weblogic.rmi.cluster.ReplicaAwareServerRef.invoke(ReplicaAwareServerRef.java:108) Error
System.err: at weblogic.rmi.internal.BasicServerRef$1.run(BasicServerRef.java:435) Error
System.err: at weblogic.security.acl.internal.AuthenticatedSubject.doAs(AuthenticatedSubject.java:363) Error
System.err: at weblogic.security.service.SecurityManager.runAs(SecurityManager.java:147) Error
System.err: at weblogic.rmi.internal.BasicServerRef.handleRequest(BasicServerRef.java:430) Error
System.err: at weblogic.rmi.internal.BasicExecuteRequest.execute(BasicExecuteRequest.java:35) Error
System.err: at weblogic.kernel.ExecuteThread.execute(ExecuteThread.java:224) Error
System.err: at weblogic.kernel.ExecuteThread.run(ExecuteThread.java:183) Error
Error: javax.naming.NameNotFoundException: Unable to resolve ‘BTQueueConnectionFactory’ Resolved [Root exception is javax.naming.NameNotFoundException: Unable to resolve 'BTQueueConnectionFactory' Resolved ]; remaining name ‘BTQueueConnectionFactory’
Error: at weblogic.rjvm.BasicOutboundRequest.sendReceive(BasicOutboundRequest.java:108)
at weblogic.rmi.cluster.ReplicaAwareRemoteRef.invoke(ReplicaAwareRemoteRef.java:290)
at weblogic.rmi.cluster.ReplicaAwareRemoteRef.invoke(ReplicaAwareRemoteRef.java:248)
at weblogic.jndi.internal.ServerNamingNode_815_WLStub.lookup(Unknown Source)
at weblogic.jndi.internal.WLContextImpl.lookup(WLContextImpl.java:375)
at weblogic.jndi.internal.WLContextImpl.lookup(WLContextImpl.java:363)
at javax.naming.InitialContext.lookup(InitialContext.java:351)
at Actions.init(Actions.java:52)
Caused by: javax.naming.NameNotFoundException: Unable to resolve ‘BTQueueConnectionFactory’ Resolved
at weblogic.jndi.internal.BasicNamingNode.newNameNotFoundException(BasicNamingNode.java:924)
at weblogic.jndi.internal.BasicNamingNode.lookupHere(BasicNamingNode.java:230)
at weblogic.jndi.internal.ServerNamingNode.lookupHere(ServerNamingNode.java:154)
at weblogic.jndi.internal.BasicNamingNode.lookup(BasicNamingNode.java:188)
at weblogic.jndi.internal.RootNamingNode_WLSkel.invoke(Unknown Source)
at weblogic.rmi.internal.BasicServerRef.invoke(BasicServerRef.java:492)
at weblogic.rmi.cluster.ReplicaAwareServerRef.invoke(ReplicaAwareServerRef.java:108)
at weblogic.rmi.internal.BasicServerRef$1.run(BasicServerRef.java:435)
at weblogic.security.acl.internal.AuthenticatedSubject.doAs(AuthenticatedSubject.java:363)
at weblogic.security.service.SecurityManager.runAs(SecurityManager.java:147)
at weblogic.rmi.internal.BasicServerRef.handleRequest(BasicServerRef.java:430)
Vuser Terminated.
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.
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.
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
Tim,
An informative post ! I was searching for some information on load testing weblogic messages. This entry is a good starting point.
Did you record these things from the weblogic console or you wrote it from the scratch by understanding the individual calls & by filtering the messages out of them ?
My requirement is that, I need to use Rational Robot & Test Manager to test our weblogic system (Messages). I ‘ve good experience in LR (not with webservices protocol though).
You have used Java Vuser. What about webservices protocol ? Can we use them for testing these messages ? which one would be apt ? Do you have any idea on Rational tools & their support for this kind of testing ?
I wrote it from scratch in a simple java class then transferred the logic to LR. If u were doing soap over jms u would still need to do it in java AFAIK. Webservices typically http…
Hi,
I am facing the problem in Java Vuser.
I need to publish the xml to the QUEUE.when I used the above script and modified accordingly
this is the error I am getting
Error: System.err: java.lang.NullPointerException Error
System.err: at Actions.action(Actions.java:112) Error
Error: java.lang.NullPointerException
Error: at Actions.action(Actions.java:112)
Any suggestions on how to measure the response time for an asynchronous queue? To clarify, the system under test:
- receives a message on one queue (upstream side)
- publishes a message on another queue (downstream side)
- an operation may be performed on a file detailed in the XML of the original message
All I’m measuring at the moment is how long the first queue takes to process the message sent to it and to respond with a green light.
Hi,
Could u provide the code that connects to a sonic queue from Loadrunner.Awaiting for ur reply..
Thanks in advance…