This site contains the documentation that is relevant to older WSO2 product versions and offerings.
For the latest WSO2 documentation, visit https://wso2.com/documentation/.
Integrating with WSO2 AS
In the sections that follow, we will look at how web applications deployed in WSO2 Application Server (WSO2 AS) can communicate with WSO2 Message Broker (WSO2 MB) as JMS subscribers and JMS publishers.
Setting up WSO2 Message Broker
Follow the steps given below to start WSO2 MB.
Download and install WSO2 MB.
- Start WSO2 MB by executing one of the following startup scripts:
- In Linux:
<MB_HOME>/bin/wso2server.sh
- In Windows:
<MB_HOME>/bin/wso2server.bat
- In Linux:
Note that WSO2 MB must be up and running before starting the application server.
Setting up WSO2 AS
Follow the steps given below to set up and start the application server.
Download and install WSO2 AS.
To avoid a port conflict with WSO2 MB, apply a port offset for WSO2 AS in the
carbon.xml
file (stored in the<MB_HOME>/repository/conf
folder). See the following example:<Offset>1</Offset>
Since all WSO2 products use the same port (9443) in the default configuration, it is not possible to start multiple WSO2 products using the default configurations in the same environment, at the same time. Therefore, using the port offset, you are making sure that each product is started on a different port.
Open the
axis2.xml
file stored in the<AS_HOME>/repository/conf/axis2
folder and enable the JMS transport receiver for WSO2 MB by uncommenting the following:<!--Configure for JMS transport support with WSO2 MB 2.x.x --> <transportReceiver name="jms" class="org.apache.axis2.transport.jms.JMSListener"> <parameter name="myTopicConnectionFactory" locked="false"> <parameter name="java.naming.factory.initial" locked="false">org.wso2.andes.jndi.PropertiesFileInitialContextFactory</parameter> <parameter name="java.naming.provider.url" locked="false">repository/conf/jndi.properties</parameter> <parameter name="transport.jms.ConnectionFactoryJNDIName" locked="false">TopicConnectionFactory</parameter> <parameter name="transport.jms.ConnectionFactoryType" locked="false">topic</parameter> </parameter> <parameter name="myQueueConnectionFactory" locked="false"> <parameter name="java.naming.factory.initial" locked="false">org.wso2.andes.jndi.PropertiesFileInitialContextFactory</parameter> <parameter name="java.naming.provider.url" locked="false">repository/conf/jndi.properties</parameter> <parameter name="transport.jms.ConnectionFactoryJNDIName" locked="false">QueueConnectionFactory</parameter> <parameter name="transport.jms.ConnectionFactoryType" locked="false">queue</parameter> </parameter> <parameter name="default" locked="false"> <parameter name="java.naming.factory.initial" locked="false">org.wso2.andes.jndi.PropertiesFileInitialContextFactory</parameter> <parameter name="java.naming.provider.url" locked="false">repository/conf/jndi.properties</parameter> <parameter name="transport.jms.ConnectionFactoryJNDIName" locked="false">QueueConnectionFactory</parameter> <parameter name="transport.jms.ConnectionFactoryType" locked="false">queue</parameter> </parameter> </transportReceiver>
Uncomment the
<transport sender>
block for JMS in the same file as follows:<!-- uncomment this and configure to use connection pools for sending messages> <transportSender name="jms" class="org.apache.axis2.transport.jms.JMSSender"/>
Add the following
jndi.properties
file to the<AS_HOME>/repository/conf
directory to make sure that WSO2 AS is pointing to the running message broker.# 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'
- Copy the following JAR files from the
<MB_HOME>/client-lib
folder to the<AS_HOME>/repository/components/lib
folder.andes-client-3.1.1
geronimo-jms_1.1_spec-1.1.0.wso2v1
log4j-1.2.13
org.wso2.carbon.logging-4.4.1
org.wso2.securevault-1.0.0-wso2v2
slf4j-1.5.10.wso2v1
Download the
axis2-transport-all-1.0.0.jar
from here and add it to the<AS_HOME>/repository/components/lib
directory.Save all the files.
- Now, start WSO2 AS by executing the startup script:
- In Linux:
<AS_HOME>/bin/wso2server.sh
- In Windows:
<AS_HOME>/bin/wso2server.bat
- In Linux:
Developing a web application (JMS Subscriber/Publisher)
To create a web application that can subscribe/publish to a queue or topic in WSO2 MB, you will need to write a JMS client (subscriber/publisher) and build it as a web application (WAR file), which can be deployed in the application server.
Follow the steps given below to build a web application that can subscribe and publish to a queue in WSO2 MB.
Step 1: Writing the JMS client
First, we will write a JMS client that subscribes to a queue in WSO2 MB: Create a java project using the source files given below and compile it.
Once you build the above client, you will have the following class files:
- JmsQueue.class
- SampleQueueReceiver.class
- SampleQueueSender.class
Step 2: Building the web application
Now, let's build a web application using the source files (JMS client) given above. This web application will also have an interface for invoking the JMS client. Follow the steps given below.
Create a folder structure in your local machine by following the steps given below.
Create the following folder structure in your local machine:
-WebApp/ -WEB-INF/ -lib/ -classes/ -MyPackage/ -web.xml Index.html
And the class files you developed in step1 to the
WEB-INF/lib/classes/MyPackage
directory. You can download these class files from here.Update the
web.xml
file with the following content:<?xml version="1.0" encoding="ISO-8859-1"?> <web-app xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd" version="2.4"> <display-name>JMS Queue Sample Web Application</display-name> <description> This is a sample web application which sends and receives queue message using wso2 message broker. </description> <servlet> <servlet-name>JMSQueueServlet</servlet-name> <servlet-class>mypackage.JmsQueue</servlet-class> </servlet> <servlet-mapping> <servlet-name>JMSQueueServlet</servlet-name> <url-pattern>/jmsqueue</url-pattern> </servlet-mapping> </web-app>
- Copy the JARs in the
<MB_HOME>/client-lib
directory to theWEB-INF/lib
directory. Update the
index.html
file with the following content:<html> <head> <title>JMS Queue Sample Web Application</title> </head> <body bgcolor=white> <table border="0"> <tr> <td> <h1>Sample Queue Web Application</h1> </td> </tr> <tr> <td> <p>This is the home page for a sample web application which sends and receives queue messages using wso2 message broker.</p> </td> </tr> </table> <p>Please click on following link to run the sample : <ul> <li><a href="jmsqueue">Queue send receive sample servlet</a></li> </ul> </body> </html>
Your
<WEBAPP_HOME>
directory should now have the following content:-WebApp/ -WEB-INF/ -lib/ - andes-client-3.0.1.jar - log4j-1.2.13.jar - org.wso2.securevault-1.0.0-wso2v2.jar - geronimo-jms_1.1_spec-1.1.0.wso2v1.jar - org.wso2.carbon.logging-4.4.1.jar - slf4j-1.5.10.wso2v1.jar -classes/ -MyPackage/ - JmsQueue.java - SampleQueueReceiver.java - SampleQueueSender.java -web.xml Index.html
Open a terminal and navigate to the
<WEBAPP_HOME>
folder.Execute the following command from the terminal in order to create the .war file:
Jar -cvf jmsQueue.war *
jmsQueue.war
file in the WebApp
folder.Deploying the web application in WSO2 AS
You can now deploy the jmsQueue
WAR file in WSO2 AS using one of the following options:
Log in to the management console of WSO2 AS and click Web Applications under Applications in the navigator to open the Upload Web Applications screen. Now you can upload the
jmsQueue.war
file to the server.Alternatively, you can simply add the WAR file to the
<AS_HOME>/repository/deployment/server/webapps
directory.
Testing the web application with WSO2 MB
Follow the steps given below to test how these JMS clients communicate with WSO2 MB.
- Be sure that the WSO2 MB server is started.
- Log in to the management console of WSO2 AS and invoke the
jmsQueue
web application. - Click Queue send receive sample servlet in the web application to execute the JMS queue send-receive sample operation.
- You can verify this from the console logs of the broker as well: A subscription has been added and deleted for the queue named "testQueue".