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.


Sunday, July 19, 2015

How to browse the H2 database management tool in WSO2 products

Hi, in this blog post I shall show you how to access and view the H2 DB management tool that is shipped with all WSO2 products.


This can be easily done by following the below steps.

Step 1 - Download a WSO2 product


For this example I am using WSO2 ESB but this configuration is common to most WSO2 products which can be downloaded from here.

Step 2 - Go to carbon.xml


Extract the downloaded product to a desired location and open the carbon.xml which is located at <ESB_HOME>/repository/conf.

Step 3 - Edit the carbon.xml


Un-comment H2 DB configuration as shown below.

<!--H2DatabaseConfiguration>
        <property name="web" />
        <property name="webPort">8082</property>
        <property name="webAllowOthers" />
        <!-- <property name="webSSL" />
        <property name="tcp" />
        <property name="tcpPort">9092</property>
        <property name="tcpAllowOthers" />
        <property name="tcpSSL" />
        <property name="pg" />
        <property name="pgPort">5435</property>
        <property name="pgAllowOthers" />
        <property name="trace" />
        <property name="baseDir">${carbon.home}</property> -->
    </H2DatabaseConfiguration-->

Now start the ESB from wso2server.sh / wso2server.bat depending on the OS you are using which is located at  <ESB_HOME>/bin




Step 4 - View H2 DB Management tool in browser 

Open the browser and go to http://localhost:8082/ and give the JDBC URL which is similar to <ESB_HOME>/repository/database/WSO2CARBON_DB and test the connection. 





When it displays successful. Then click on "Connect"

You can see the databases and query it as you like.







Sunday, July 12, 2015

Create a Apache Axis2 web service using eclipse and monitor requests / responses using TCPMon



This blog post will guide you to create a Apache Axis2 web service and a client plus to monitor the requests and responses via TCPMon.



Step 1 - Create a axis2 web service and client


I found this descriptive blog post which guides you on how to create a axis2 web service using eclipse and also create a client to consume the service. After creating the service and the client lets move to the next step.


Step 2 - Run TCPMon



TCPMon can be found in almost all the WSO2 products here is the link to download WSO2 Application Server. After downloading the WSO2 AS extract it to a desired location. Then go to {WSO2ASHome}/bin folder.

Run "tcpmon.bat" file if your using Windows as the OS or run the "tcpmon.sh" if you are on a Linux distro.

Step 3 - Create a listener in TCPMon


By creating a listener we can monitor the requests and responses that flows between the web service and client. This is where TCPMon comes in to play.

Add the below settings in TCPMon – Admin section to set up a listener

  1. Listen Port# = 8585(Port which the TCPMon will listen to)
  2. "Act as a.." section = Select “Listener” radio button
  3. Target Host-name = 127.0.0.1 (tomcat server host ip)
  4. Target port = 8080 (the port which the tomcat server is utilizing)


You can also add proxy support and/or simulate a slow connection scenario. For this demonstration I have added a time delay to simulate a slow network (refer below image). After you are done with the settings click on “Add”.




Step 4 - Modify the client stub class


Now that we set up a listener lets point the client to the listener port. Before the configuration change make sure the created server and client is working. Next,in your client code simply pass the endpoint to the constructor of the stub class and your ready to go. You can set your desired endpoint as shown in the below figure. Line number 12 if you are using the soap11 endpoint or line number 13 if you are using hoping to use soap12 endpoint.





Step 5 - View requests/responses in TCPMon


Run the client application and go to the TCPMon you can see the requests and responses.
Below are couple of screen shots of TCPMon. Note that the "Elapsed Time" is a bit long because I configured a slow connection.

Without slow simulation


With slow simulation



This way you can monitor and simulate different scenarios to check your web service and how the client will consume it.