...
Before you begin
Install WSO2 MB and Apache JMeter download JMS clients as explained below.
- Download and start WSO2 MB
- Download and start Apache JMetersample JMS clients
Download and start WSO2 MB
Follow the steps given below to download and start your producta WSO2 MB instance.
- Download WSO2 Message Broker from here.
- Extract the zip ZIP file to a location in on your computer. This location will be referred to as
<MB_HOME>
from hereon. - To start the product: Open a terminal and , navigate to the
<MB_HOME>/bin
directory where all the startup scripts are stored and run the startup script:- On Windows:
wso2server.bat
- On Linux:
sh wso2server.sh
- On Windows:
The URL of the management console will be printed in the terminal as follows:
Code Block INFO {org.wso2.carbon.ui.internal.CarbonUIServiceComponent} - Mgt Console URL : https://10.100.5.65:9443/carbon/
Copy this URL to your browser to open the management console. Note the IP address used in the URL, which is '10.100.5.65' in the above scenario. You will need this IP address later when you connect to the MB node from an external client. Therefore, lets change it to
localhost
to make this quick start process simpler.Code Block INFO {org.wso2.carbon.ui.internal.CarbonUIServiceComponent} - Mgt Console URL : https://localhost:9443/carbon/
Download and start Apache JMeter
In this quick start guide, we will be using Apache JMeter for the purpose of simulating how a JMS client sends messages to WSO2 MB and how such a client subscribes to topics and queues in WSO2 MB. Therefore, let us install and start Apache JMeter by following the steps given below.
Download Apache JMeter from here and install it. The location of your JMeter folder will be referred to as
<JMeter_HOME>
from hereon.Note Note that JMeter 2.13 version is used for this quick start guide.
- Copy the following JARs from the
<MB_HOME>/client-lib
directory to the<JMeter_Home>/lib
folder:andes-client-3.1.1.jar
geronimo-jms_1.1_spec-1.1.0.wso2v1.jar
org.wso2.carbon.logging-4.4.1.jar
org.wso2.securevault-1.0.0-wso2v2.jar
- Start the JMeter by executing the following script from the
<JMeter_Home>/bin
folder:- On windows:
jmeter.bat
- On Linux:
sh jmeter.sh
- On windows:
Working with queues
In the following steps, we will go through the basics of creating a queue in WSO2 MB and setting up a JMS client as a subscriber and publisher.
...
Download sample JMS clients
WSO2 Message Broker is used for brokering messages between JMS clients. We will use the following sample JMS clients in this quick start guide to see how this process works.
- Click this link to download the
QuickStartClients.zip
file, which contains the following sample clients.- JMS queue publisher
- JMS queue subscriber
- JMS topic publisher
- JMS topic subscriber
- JMS durable topic subscriber
- Extract this file to a location on your computer. We will call this
<JMS_CLIENTS_HOME>
from hereon.
You will need Apache Ant to execute the above JMS clients. Download Apache Ant using homebrew.
...
Working with Queues
Let's try out a simple scenario of brokering messages using a queue in WSO2 MB.
Step 1: Create a queue in WSO2 MB
We will now create a queue in WSO2 MB, using the product's management console. Follow the instructions given below.
- Log in to the management console using the credentials of the default system administrator: admin/admin.
You will now be logging into the super tenant domain. - In the Main tab, click Queues -> Add. The Add Queue screen will open.
- Enter 'MyFirstQueuetestQueue' as the name in the Queue Name field as shown below.
- Click Add Queue and the new queue will be listed in the Queue List page as shown below.
You can access the Queue List page by clicking Queues -> List in the Main tab of the navigator.
Step 2:
...
Publish messages to the queue
We will now set up Apache JMeter as a JMS publisher to the queue we created in the previous step. Follow the instructions given below.
Create the following
jndiqueues.properties
file and save it to a location in your system. The details in this file will establish the connection between your JMS publisher and the MB node you installed.Code Block # register some connection factories # connectionfactory.[jndiname] = [ConnectionURL] connectionfactory.QueueConnectionFactory = amqp://admin:admin@clientID/carbon?brokerlist='tcp://localhost:5672' # register some queues in JNDI using the form # queue.[jndiName] = [physicalName] queue.MyFirstQueue = MyFirstQueue
Note Note that we are using
localhost
as the IP address, which is the same IP we used for starting the management console of WSO2 MB.- Go to the JMeter UI and create a JMS publisher as explained below.
- Create a new test plan in JMeter: Right-click on Test Plan (in the left navigator) and go to Add -> Threads (Users) -> Thread Group.
- The new thread group will now be listed in the left navigator as a test plan.
- Right-click on the new test plan and go to Add -> Sampler -> JMS Publisher.
- Name the publisher as 'JMS Queue Publisher'.
- You will now have a JMS Publisher node in the left navigator. Select this node and enter the following details:
- In the Initial Context Factory field, enter
org.wso2.andes.jndi.PropertiesFileInitialContextFactory
. - The connection details you specified in the
jndiqueues.properties
file should be entered for the JMS Publisher as shown below.
- Provider URL: This should be the location where you have the
jndiqueues.properties
file saved. - Connection Factory: This should be set to
QueueConnectionFactory
. - Destination: MyFirstQueue.
- Provider URL: This should be the location where you have the
- Enter the values in the Expiration and Priority fields to zero (0).
- In the Initial Context Factory field, enter
- Enter the message that you want to publish to the queue in the relevant field.
Save the information. You now have a JMS client ready to send messages to the 'MyFirstQueue' queue in your MB server.
Expand title Click here to view these details in JMeter
- Execute the JMeter publisher.
- Go back to the management console of WSO2 MB and go to the Queue List page from the navigator. See that that the MyFirstQueue queue has received one message.
- Click Browse to view details of the message that has been published:
Step 3: Subscribing to queues
We will now set up Apache JMeter as a JMS subscriber for the queue we created in the previous step. Follow the instructions given below.
- Go to the JMeter UI and create a JMS subscriber as explained below.
- Create a new test plan: Right-click on Test Plan (in the left navigator) and go to Add -> Threads (Users) -> Thread Group.
- The new thread group will now be listed in the left navigator as a test plan.
- Right-click on the new test plan and go to Add -> Sampler -> JMS Subscriber.
- Name the subscriber 'JMS Queue Subscriber'.
- You will now have a JMS Queue Subscriber node in the left navigator. Select this node and enter the following details:
- In the Initial Context Factory field, enter
org.wso2.andes.jndi.PropertiesFileInitialContextFactory
. - The connection details you specified in the
jndiqueues.properties
file should be entered for the JMS Subscriber as shown below.
- Provider URL: This should be the location where you have the
jndiqueues.properties
file saved. - Connection Factory: This should be set to
QueueConnectionFactory
. - Destination: MyFirstQueue.
- Provider URL: This should be the location where you have the
- In the Initial Context Factory field, enter
- Right-click on the new test plan and go to Add -> Listener -> View Results in Tree. This will create a listener node in the the JMeter navigator for analysing the output of the subscription.
- Save the information. You now have a JMS client subscribed to the 'MyFirstQueue' queue in your MB server.
Execute the JMeter script. This will create a subscription to the MyFirstQueue queue in your MB server, and the message that was already published to that queue will be immediately consumed.
Select the View Results in Tree node in the JMeter navigator and go to the Response data tab. You can now see that the message from the MyFirstQueue queue has been received by the subscriber.
Go back to the management console of WSO2 MB and view the Queue List. See that the number of messages published to the MyFirstQueue has reverted to zero.
Managing unconsumed subscriptions
In the above example, we saw that the subscriber immediately consumes the message that is published to WSO2 MB. The following illustrates how subscriptions can be managed if a published message is not available to be consumed.
- Lets us create another subscription to the same queue (MyFirstQueue) in WSO2 MB by simply repeating step 3 given above.
- Go to the management console of WSO2 MB and go to Subscriptions -> Queue Subscription List in the Main tab. See that the subscription is listed as shown below.
The Queue Subscription List page shows all the subscriptions that are waiting for published messages.
Working with topics
In the following steps, we will go through the basics of creating topics in WSO2 MB by creating a simply hierarchy of topics and then setting up JMS clients as the subscriber and publisher for the topics.
Step 1: Creating the topic hierarchy
We will now create the topics and sub topics, so that you have the following hierarchy:
To add the topics and sub topics:
...
You can use the queue publisher JMS client to publish messages to this queue. Follow the steps given below.
- Open a command prompt and navigate to the <JMS_CLIENTS_HOME> directory on your computer.
Execute the following command, which will publish 10 messages to the queue:
Code Block ant queuePublisher
- Go to the management console.
- In the Main tab, click TopicsQueues -> Add. The Add Topic screen will open.
- Enter 'Games' as the topic name in the Topic field.
- Click Add Topic and the new topic will be listed in the Topic List page as shown below.
You can access the Topic List page by clicking Topic -> List in the Main tab of the navigator. - Click Games in the topic list. This will open the following options:
- Click Add Subtopic to open the Add Sub Topic screen.
- Enter 'Football' as the subtopic name and click Add Topic. You will now have the following topic structure:
- Repeat the steps to add the remaining subtopics until you get the complete topics hierarchy.
Step 2: Subscribing to topics
We will now set up Apache JMeter as a JMS subscriber for the topics we created in the previous step. Follow the instructions given below.
Create the following
jnditopics.properties
file and save it to a location in your system. The details in this file will establish the connection between your JMS subscriber and the MB node.Code Block # register some connection factories # connectionfactory.[jndiname] = [ConnectionURL] connectionfactory.TopicConnectionFactory = amqp://admin:admin@clientID/carbon?brokerlist='tcp://localhost:5672' # register some topics in JNDI using the form # topic.[jndiName] = [physicalName] topic.Games = Games
Note Note that we are using
localhost
as the IP address, which is the same IP we used for starting the management console of WSO2 MB.- Start a new JMeter instance by executing the following script from the
<JMeter_Home>/bin
folder:- On windows:
jmeter.bat
- On Linux:
sh jmeter.sh
- On windows:
- Go to the JMeter UI and create a JMS subscriber as explained below.
- Create a new test plan: Right-click Test Plan (in the left navigator) and go to Add -> Threads (Users) -> Thread Group.
- The new thread group will now be listed in the left navigator as a test plan.
- Right-click on the new test plan and go to Add -> Sampler -> JMS Subscriber.
- Name this subscriber Games Subscriber.
- You will now have a JMS Subscriber node in the left navigator. Select this node and enter the following details:
- In the Initial Context Factory field, enter
org.wso2.andes.jndi.PropertiesFileInitialContextFactory
. - The connection details you specified in the
jnditopics.properties
file should be entered for the JMS Subscriber as shown below.
- Provider URL: This should be the location where you have the
jndi.properties
file saved. - Connection Factory: This should be set to
TopicConnectionFactory
. - Destination: Games
- Provider URL: This should be the location where you have the
- In the Initial Context Factory field, enter
- Right-click on the new test plan and go to Add -> Listener -> View Results in Tree. This will create a listener node in the JMeter navigator for analysing the output of the subscription.
Save the information. You now have a JMS client subscribed to the 'Games' topic or any of its child topics (Football, Germany or Brazil).
Expand title Click here to view these details in JMeter
Execute the JMeter script.
Now, go to the management console of WSO2 MB and go to Main -> Subscriptions -> Topic Subscription List. Your subscription will be listed as a temporary topic subscription:In the next section, let's look at how this subscription will be served when a message is published to the 'Games' topic.
Step 3: Publishing messages to topics
We will now set up Apache JMeter as a JMS publisher to the 'Games' topic that we created in the previous step. Follow the instructions given below.
Start a new JMeter instance by executing the following script from the
<JMeter_Home>/bin
folder:- On windows:
jmeter.bat
- On Linux:
sh jmeter.sh
- On windows:
Create a new test plan in JMeter: Right-click on Test Plan (in the left navigator) and go to Add -> Threads (Users) -> Thread Group.
- The new thread group will now be listed in the left navigator as a test plan.
- Right-click on the new test plan and go to Add -> Sampler -> JMS Publisher.
- Name this publisher Games Publisher. We will be using this publisher to publish messages relevant to the 'Games' topic.
- You will now have a Games Publisher node in the left navigator. Select this node and enter the following details:
- In the Initial Context Factory field, enter
org.wso2.andes.jndi.PropertiesFileInitialContextFactory
. - The connection details you specified in the
jnditopics.properties
file should be entered for the JMS Publisher as shown below.- Provider URL: This should be the location where you have the
jnditopics.properties
file saved. - Connection Factory: This should be set to
TopicConnectionFactory
. - Destination: Games
- Enter the values in the Expiration and Priority fields to zero (0).
- Provider URL: This should be the location where you have the
- Enter the message that you want to publish to the topic in the relevant field.
- In the Initial Context Factory field, enter
- Save the information. You now have a JMS client ready to send messages.
- Execute the JMeter publisher.
- Go back to the management console of WSO2 MB and go to Subscriptions -> Topic Subscription List in the Main tab. See that the temporary topic subscription is now removed, because the subscription has now been served by a message.
Monitoring statistics
WSO2 MB consists of many capabilities that can be used for monitoring and analysis. Follow the steps given below for a quick demonstration on how to analyse the statistics corresponding to the work you did with your MB server in the previous sections of this quick start guide.
- In the management console of WSO2 MB, go to the Monitor tab. The following monitoring options will be available to you:
For the purpose of this demonstration, let's use Java Metrics for monitoring: Click Messaging Metrics to open the View Metrics screen.
Note Note that all of the options for viewing statistics are selected in the metric dashboard.
- Shown below are some of these statistics.
The following graph shows how the number of queue subscriptions and topic subscriptions have varied during the time that you worked with you MB server.
Expand title Publish and subscribe The following graph displays how the number of messages received by the MB server and the number of acknowledgements from subscriber clients have varied with time.
Expand title Received messages and acknowledgements The following graph shows how much time the MB server has taken to read data from the database.
Expand title Database read time The following graph shows the rate (reads per second) at which the MB server reads data from the database.
Expand title Database read rate The following graph shows how much time the MB server has taken to write data to the database.
Expand title Database write time The following graph shows the rate (writes per second) at which the MB server writes data to the database.
Expand title Database write rate
Shown above are only some of the monitoring capabilities available in WSO2 MB. See the documentation on monitoring and statistics for more information on how to use the other capabilities.
...
- . You can see that 10 messages have been published to the queue as shown below.
- Click Browse to see details of the messages received.
Step 3: Subscribe to the queue and consume messages
The queue subscriber JMS client will be used for this purpose. Follow the steps given below.
- Open a command prompt and navigate to the location of your JMS clients.
Execute the following command, which will subscribe to the queue and consume the available messages.
Code Block ant queueSubscriber
- Go to the management console.
- In the Main tab, click Queues -> List. You can see that the 10 messages that were stored in the queue have been successfully consumed by the subscriber.
- You can verify this from the terminal log.