2013/08/06
6 Aug, 2013

How to Use Apache JMeter as a JMS Queue/Topic Client with WSO2 Message Broker

  • Ishara Premadasa
  • Solutions Engineer - WSO2
Archived Content
This article is provided for historical perspective only, and may not reflect current conditions. Please refer to relevant product page for more up-to-date product information and resources.

Introduction

There are many scenarios that require to be subscribed or published to a JMS queue or a topic within WSO2 Message Broker. A JMS client can be used for this purpose and the general practice is to use a sample JMS Java client code to get connected to a queue or a topic. Apache JMeter is an open-source load testing application that is generally used to perform load and performance tests on resources. However, Apache JMeter can be very easily configured as a simple JMS client that can connect and perform queue/topic operations in WSO2 Message Broker.

Applies to

WSO2 Message Broker 2.1.0
Apache JMeter 2.9

Content

  • Adding required client libraries to JMeter
  • Creating a JMS Subscriber for WSO2 Message Broker using JMeter
  • Creating a JMS Publisher for WSO2 Message Broker using JMeter

1. Adding required client libraries to JMeter

First, go to the MB_HOME/client-lib directory and copy the following libraries into the JMETER_HOME/lib directory from here. Usually, it is only required to have the following three libraries in the JMeter 'lib' directory; however, if there are any visible errors, copy the remaining few libraries as well.

  • andes-client-0.13.wso2v8.jar
  • geronimo-jms_1.1_spec-1.1.0.wso2v1.jar
  • slf4j-1.5.10.wso2v1.jar

2. Creating a JMS Subscriber for WSO2 Message Broker using JMeter

Now let's create a JMS Subscriber using Apache JMeter.

Create a new test plan with a suitable name. I have named it 'MB Subscriber Test Plan' here. Go to 'MB Subscriber Test Plan' --> Add --> Threads (users) --> Thread group and create a new thread group as follows.

Name the thread group as 'Subscriber thread'.

This thread group acts as a set of users who are trying to subscribe to a certain queue in the Message Broker. By changing the values in the 'Thread Properties' section of the Thread Group window, we can configure the required properties of the subscriber threads.

JMS Subscriber Thread

Details of the each configurable property for the thread group as follows.

  1. Number of threads (users): The amount of threads needs to be started in this thread group for the test plan. In our case, this is the number of subscribers that were started in parallel with the thread group.
  2. Ramp-Up Period (in seconds): This is the time delay between the starting of two threads. For example it this value is set to '1' and there are 5 threads are used, JMeter will start one thread then will wait one second and start the next thread. As I have set the value to '0' here, all the subscriber threads will start immediately.
  3. Loop count: How many turns that the thread will run before it exits the system. As this count is set to '5' here, the subsciber thread will excute the 'receive()' operation 5 times for this single thread. The loop count can be set as 'forever' if the thread needs to be running till the JMeter is closed.

Now let's create a Sample JMS Subscriber under this thread group. Go to 'Subscriber Thread' --> Add --> Sampler --> JMS Subscriber to add a new subscriber. This subscriber will run as a thread in the previously created 'Subscriber Thread' group with the configured broker parameters shown below.

JMS Subscriber Client

Apache JMeter's JMS subscriber window provides a rich set of properties to be configured for a sample subscriber. In this example, we have configured only the required parameters that need to get the subscriber connected to WSO2 Message Broker. The description of the required values for each of these parameters are given below.

  • Initial context factory: The JNDI initial context factory implementation class in WSO2 Message Broker. The value for this is org.wso2.andes.jndi.PropertiesFileInitialContextFactory.
  • Provider URL: We do not enter the original provider URL here, and instead, we provide the path to a custom JNDI properties file where the provider URL is defined in that file. I have created a sample JNDI propeties file named 'myjndi.properties' and have added the complete path to the file into this field. The content of the myjndi.properties is as follows.
#  Copyright (c) 2011, WSO2 Inc. (https://wso2.com) All Rights Reserved.
#
#  Licensed under the Apache License, Version 2.0 (the "License");
#  you may not use this file except in compliance with the License.
#  You may obtain a copy of the License at
#
#        https://www.apache.org/licenses/LICENSE-2.0
#
#  Unless required by applicable law or agreed to in writing, software
#  distributed under the License is distributed on an "AS IS" BASIS,
#  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
#  See the License for the specific language governing permissions and
#  limitations under the License.
#

# register some connection factories
# connectionfactory.[jndiname] = [ConnectionURL]
connectionfactory.QueueConnectionfactory = amqp://admin:admin@clientID/carbon?brokerlist='tcp://localhost:5672'
connectionfactory.TopicConnectionFactory = amqp://admin:admin@clientID/carbon?brokerlist='tcp://localhost:5672'
# register some queues in JNDI using the form
# queue.[jndiName] = [physicalName]
queue.MyQueue = MyQueue

# register some topics in JNDI using the form
# topic.[jndiName] = [physicalName]
#topic.MyTopic = MyTopic
  • Connection factory: Enter the JNDI name of connection factory that is defined in the 'myjndi.properties' file as the broker URL. In this example, it is QueueConnectionfactory where this is defined as connectionfactory.QueueConnectionfactory = amqp://admin:admin@clientID/carbon?brokerlist='tcp://localhost:5672'
  • Destination: As we are going to subscribe to a queue, enter the name of the queue as the 'Destination'. Prior to that, the queue name needs to be defined in the 'myjndi.properties' file. In our file this is defined as queue.MyQueue = MyQueue. Therefore, enter the destination name as 'MyQueue'. If it is required to subscribe for a JMs Topic, simply add the topic name in this field while configuring the correct connection factory for the topic.

The above four parameters are required whether you are going to publish/subscribe to a topic/queue, in each scenario. Apart from these, other properties of the subscriber window can also be added according to the user's requirement. As an example, you can add a 'Durable Subscription ID' when making a durable subscription for a JMS topic created in WSO2 Message Broker. Furthermore, as the JMS subscriber uses a MessageListener or MessageConsumer's receive() method, a timeout value can be added in the 'Timeout (milliseconds)' field where the listener or consumer will be auto closed once it hits timeout.

Now save all these configurations, start WSO2 Message Broker 2.1.0 and log in to the admin console. Thereafter, you can run the 'JMS Subscriber' from Apache JMeter to observe if it makes a subscription and receives messages from the queue 'MyQueue'. In our example, we have created only one subscriber thread that will loop five times to receive the messages and closes the JMS subscriber thereafter.

3. Creating a JMS Publisher for WSO2 Message Broker using JMeter

Secondly, let's create a JMS Publisher to send messages to a queue in WSO2 Message Broker.

In creating a JMS Publisher, you have to first follow the steps in section 1, and create a new Test Plan and a Thread group. An example Thread group is shown in the snapshot below.

JMS Publisher Thread

For this example, we have created 5 publisher threads (users) where each thread will loop 5 times before getting closed. Now add a JMS Publisher under this thread group by following 'Publisher Thread' --> Add --> Sampler --> JMS Publisher.

The required configuration entries are just the same as in the JMS Subscriber. Apart from that, the Publisher window has options of selecting the message type to send, sending the message using a provided text area or by using a file etc., which can be customized according to user requirements. The 'Number of samples to aggregate' can be used to enter how many messages need to be sent from each thread at a single time.

JMS Publisher Client

Save the JMS Publisher and run it. As we have created five publisher threads, each one will loop five times when sending a sample text messages each time. Therefore, the JMS Publisher we created will send 25 messages to the queue 'MyQueue' in WSO2 Message Broker. Now go to the console and verify if all the messages are there.

Summary

When it is required to use a JMS client to connect with WSO2 Message Broker, Apache JMeter can be easily used as a JMS Subscriber or a Publisher to a certain queue/topic in WSO2 Message Broker. The user does not need to worry about writing any sample client codes and can simply use a JMeter configuration in connecting to the broker. To this end, in this tutorial, we have provided a step-by-step guide on how to use Apache JMeter as a JMS client to WSO2 Message Broker.

Author

Ishara Premadasa, Software Engineer, WSO2 Message Broker team.

Email: [email protected]

 

About Author

  • Ishara Premadasa
  • Solutions Engineer
  • WSO2