Sunday, July 26, 2015

How to use Apache JMeter as a JMS client to publish and subscribe messages with WSO2 Message Broker


In this blog post I will describe how to use Apache JMeter to publish and subscribe to a queue via WSO2 Message Broker.


Step 1 -  Download Apache JMeter

Download Apache JMeter from the link and extract it to a desired folder.

Step 2 - Download and start WSO2 Message Broker


Download WSO2 Message Broker from the link and extract it to a desired folder. Then start the Message Broker by WSO2_MB_HOME/bin wso2server.sh or wso2server.bat file depending on the OS you are running on.

Step 3 - Add required client libraries

In order to use JMeter to pub / sub via WSO2 MB we need to add couple of jar files to JMeter. Go to WSO2_MB_HOME/client-libs and copy the below libraries to JMETER_HOME/lib folder.

  1. andes-client-2.6.0.jar
  2. geronimo-jms_1.1_spec-1.1.0.wso2v1.jar
  3. slf4j-1.5.10.wso2v1.jar
  4. log4j-1.2.13.jar
  5. org.wso2.carbon.logging-4.4.1.jar
  6. org.wso2.securevault-1.0.0-wso2v2.jar

Step 4 - Create a JNDI


To use WSO2 MB you need to create a jndi.properties file in order to create the connection. Refer below image to create a sample jndi property file. 


  1. Connection factory - give the user name and password ( admin is default user name and password ) and the IP of the broker.
  2. Give a queue name, in the example I have used the queue name is "QueOne"



jndi.properties



Step 5 -  Create a JMS Subscriber from JMeter to consume messages


Now start JMeter by navigating to JMETER_HOME/bin and run jmeter.sh / jmeter.bat depending on your OS.
To create a test plan first add a thread group and then right click on the thread group and from "Sampler" section add "JMS Subscriber".

Then fill the sampler as follows,
  1. Initial Context Factory -  org.wso2.andes.jndi.PropertiesFileInitialContextFactory
  2. Provider URL - /home/jasons/Softwares/Jmeter2/apache-jmeter-2.9/wso2mb/jndi.properties (Path to created jndi)
  3. Connection Factory - QueueConnectionFactory
  4. Destination - QueueOne

JMS Subscriber

After creating the subscriber run the subscriber ones and stop the subscriber this will create the queue in the WSO2 message broker(Note that you can manually create a queue from the Message Broker management console too)

Step 6 -  Create a JMS Publisher  

To create a publisher you can do so by creating a thread group and then from "Sampler" section add "JMS Publisher" sampler.

  1. Initial Context Factory -  org.wso2.andes.jndi.PropertiesFileInitialContextFactory
  2. Provider URL - /home/jasons/Softwares/Jmeter2/apache-jmeter-2.9/wso2mb/jndi.properties (Path to created jndi)
  3. Connection Factory - QueueConnectionFactory
  4. Destination - QueueOne
  5. Message - Provide a file or text message I have used a text messge for this example

JMS Publisher



After creating the publisher add a desired number of message count to be published this can be set from "loop count" which is located under the "Thread Group" JMeter which will publish x number of messages. For my example I have set it to 100.

Step 7 - View published message stats in Message Broker


Login  to Message Broker Management console  by going to https://localhost:9443/carbon/ provide user name and password as admin. Then you can navigate to Queues section and view the published messages and queue details.


WSO2 Message Broker console


Now run the Subscriber and the messages that was published will be consumed. You can view the details via JMeter buy adding a desired listener to examine the message status etc.


1 comment:

  1. Hi Jason - this is not working for me. Can you please help?
    https://stackoverflow.com/questions/58089651/wso2-point-to-point-messaging

    ReplyDelete