Integrating WSO2 ESB
This section describes how to integrate WSO2 Message Broker with WSO2 Enterprise Service Bus to facilitate message brokering needs of the ESB and to implement store and forward messaging pattern.
The first step is to set up WSO2 MB and WSO2 ESB.
Setting up WSO2 Message Broker
1. Download and install WSO2 MB according to the instructions in the Getting Started.
It is not possible to start multiple WSO2 products with their default configurations simultaneously in the same environment. Since all WSO2 products use the same port in their default configuration, there will be port conflicts. Therefore, to avoid port conflicts, apply a port offset in <MB_HOME>/repository/conf/carbon.xml file by changing the offset value to 1. For example,
<Ports> <!-- Ports offset. This entry will set the value of the ports defined below to the define value + Offset. e.g. Offset=2 and HTTPS port=9443 will set the effective HTTPS port to 9445 --> <Offset>1</Offset>
2. Start the Message Broker by running <MB_HOME>/bin/wso2server.sh (on Linux) or <MB_HOME>/bin/wso2server.bat (on Windows) .
Setting up WSO2 ESB
1. Download and install WSO2 ESB binary distribution. Instructions can be found in the 'Installation Guide' of the respective ESB documentation version. For example, http://docs.wso2.org/wiki/display/ESB451/Installation+Guide. The unzipped ESB distribution folder is referred to as ESB_HOME.
2. Enable the JMS transport of WSO2 ESB to communicate with the Message Broker by editing $ESB_HOME/repository/conf/axis2/axis2.xml file. Find a commented <transport receiver> block for MB 2.x.x and uncomment it.
<!--Uncomment this and configure as appropriate for JMS transport support with WSO2 MB 2.x.x --> <!--transportReceiver name="jms" class="org.apache.axis2.transport.jms.JMSListener"> ….. </parameter> </transportReceiver-->
Also, uncomment <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"/-->
3. Copy the following jar files from <MB_HOME>/clent-lib folder to <ESB_HOME>/repository/components/lib folder. T hey are client libraries required from Message Broker to ESB.
- andes-client-0.13.wso2v8
- geronimo-jms_1.1_spec-1.1.0.wso2v1
4. Open <ESB_HOME>/repository/conf/ JNDI.proerties file and point to the running Message Broker.
Use ‘carbon’ as the virtualhost. Define a queue called ‘JMSMS’. Comment out the topic as it is not needed. But, in order to avoid getting ‘javax.naming.NameNotFoundException: TopicConnectionFactory’ during server startup, point 'TopicConnectionFactory' also to the Message Broker.
# register some connection factories # connectionfactory.[jndiname] = [ConnectionURL] connectionfactory.QueueConnectionFactory = amqp://admin:admin@clientID/carbon?brokerlist='tcp://localhost:5673' connectionfactory.TopicConnectionFactory = amqp://admin:admin@clientID/carbon?brokerlist='tcp://localhost:5673' # register some queues in JNDI using the form # queue.[jndiName] = [physicalName] queue.JMSMS=JMSMS queue.StockQuotesQueue = StockQuotesQueue
The connection factory specifies the URL to be used by a client using WSO2 MB in order to connect to it. 5673 in this example is the port listening for messages on TCP when the AMQP transport is used. This port changes depending on the port offsets done in different scenarios. See Configuring a Client to Access Broker When Port Offset is Change for more information.
5. Start WSO2 ESB by running <ESB_HOME>/bin/wso2server.sh (on Linux) or <ESB_HOME>/bin/wso2server.bat (on Windows).
Both ESB and Message Broker are up and running now.
6. We need some background services to be available for testing purposes. For that, run an ANT task to deploy the “SimpleStockQuoteService” in the simple axis2server as follows.
- Navigate to <ESB_HOME>/samples/axis2Server/src/SimpleStockQuoteService and run ‘ant’ to build the sample and deploy background services.
- Next, run <ESB_HOME>/samples/axis2server/ axis2Server.sh (on Linux) to start the Axis2 server.
- Point your browser to http://127.0.0.1:9000/services/SimpleStockQuoteService?wsdl and verify that the service is running.
You now have two instances of WSO2 Message Broker and WSO2 ESB configured, up and running. Next, proceed to integrate the Message Broker with ESB, for which there are two implementation options as follows:
Integration Using JMS Endpoints and JMS Proxy Services
This section describes, through a usecase, how to integrate WSO2 Message Broker with WSO2 ESB as JMS endpoints.
Usecase
Store a message received to a http proxy of the ESB in a JMS queue. Then consume that queue, get the message and send it to the actual endpoint.
Execution Steps
1. We need to create the consumer first to make a subscription for the queue to be used in this usecase. Therefore, create a JMS proxy by the name “StockQuotesQueue”. It is the same name defined in the jndi.properties file above. The Synapse configuration for the proxy looks as follows.
<proxy xmlns="http://ws.apache.org/ns/synapse" name="StockQuotesQueue" transports="jms" statistics="disable" trace="disable" startOnLoad="true"> <target> <inSequence> <log level="full"/> <property name="OUT_ONLY" value="true"/> <send> <endpoint> <address uri="http://localhost:9000/services/SimpleStockQuoteService"/> </endpoint> </send> </inSequence> </target> <description></description> </proxy>
In the code, the consumed message from the JMS queue 'StockQuotesQueue' is logged and sent to the endpoint 'SimpleStockQuoteService'.
2. Create the HTTP proxy to send messages to the JMS Queue. Synapse configuration for this HTTP proxy is as follows. Since this is a one-way message, the property “OUT_ONLY” is set to true and “FORCE_SC_ACCEPTED” property is defined to send a 202 response to the client who invokes this proxy.
<proxy xmlns="http://ws.apache.org/ns/synapse" name="StockQuoteProxy" transports="https,http" statistics="disable" trace="disable" startOnLoad="true"> <target> <inSequence> <property name="OUT_ONLY" value="true"/> <property name="FORCE_SC_ACCEPTED" value="true" scope="axis2"/> <send> <endpoint> <address uri="jms:/StockQuotesQueue?transport.jms.ConnectionFactoryJNDIName=QueueConnectionFactory&java.naming.factory.initial=org.wso2.andes.jndi.PropertiesFileInitialContextFactory&java.naming.provider.url=repository/conf/jndi.properties&transport.jms.DestinationType=queue"/> </endpoint> </send> </inSequence> </target> <description></description> </proxy>
The message flow paths are completed. When the 'StockQuoteProxy' is invoked, it will send the message to the queue, which will be consumed by the JMS proxy 'StockQuotesQueue' and send to the actual endpoint.
Testing the Integration
Using the SOAP UI, send the following SOAP message to 'StockQuoteProxy'.
<soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope" xmlns:ser="http://services.samples" xmlns:xsd="http://services.samples/xsd"> <soap:Header/> <soap:Body> <ser:placeOrder> <!--Optional:--> <ser:order> <!--Optional:--> <xsd:price>10</xsd:price> <!--Optional:--> <xsd:quantity>100</xsd:quantity> <!--Optional:--> <xsd:symbol>IBM</xsd:symbol> </ser:order> </ser:placeOrder> </soap:Body> </soap:Envelope>
As the output, this message will be logged in the ESB console and SimpleAxis2Server’s log will be as follows:
Tue Jan 15 15:31:28 IST 2013 samples.services.SimpleStockQuoteService :: Accepted order #2 for : 100 stocks of IBM at $ 10.0
Integrate Using Message Stores and Processors
This section describes how to integrate WSO2 Message Broker with WSO2 ESB as using message stores and processors.
Execution Steps
1. Define a message store by copying and pasting the following config to source view. Alternatively you can use the message-store UI.
<messageStore name="JMSMS" class="org.wso2.carbon.message.store.persistence.jms.JMSMessageStore" xmlns="http://ws.apache.org/ns/synapse"> <parameter name="java.naming.factory.initial">org.wso2.andes.jndi.PropertiesFileInitialContextFactory</parameter> <parameter name="java.naming.provider.url">repository/conf/jndi.properties</parameter> <parameter name="store.jms.destination">JMSMS</parameter> <parameter name="store.jms.JMSSpecVersion">1.1</parameter> <parameter name="store.jms.cache.connection">false</parameter> </messageStore>
2. Define an endpoint to send the message. In this example, the backend just set-up in the previous step is used.
<endpoint name="SimpleStockQuoteService"> <address uri="http://127.0.0.1:9000/services/SimpleStockQuoteService"/> </endpoint>
3. Define a message forwarding processor as below by copying and pasting code or using the Management Console UI.
<messageProcessor class="org.apache.synapse.message.processors.forward.ScheduledMessageForwardingProcessor" name="Processor1" messageStore="JMSMS"> <parameter name="max.delivery.attempts">4</parameter> <parameter name="interval">4000</parameter> </messageProcessor>
4. Invoke the scenario use a proxy service like below.
<proxy name="InOnlyProxy" transports="https http" startOnLoad="true" trace="disable"> <target> <inSequence> <property name="FORCE_SC_ACCEPTED" value="true" scope="axis2"/> <property name="OUT_ONLY" value="true"/> <property name="target.endpoint" value="SimpleStockQuoteService"/> <log level="full"/> <store messageStore="JMSMS"/> </inSequence> </target> </proxy>
Whenever a message comes to this proxy service, it will be stored in JMS message store (which is in Message Broker, JMSMS queue). If message processor is disabled and messages are sent, you will
notice in the Message Broker's management console, the message count of JMSMS queue being increased.
Note
Described here is 'In Only' service invocation with Message Forwarding Processor. Follow the article below to implement the others.
http://wso2.org/library/articles/2011/12/implementing-store-forward-messaging-patterns-wso2esb-part-2
Testing the Integration
Using the SOAP UI, send the following SOAP message to the InOnlyProxy.
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ser="http://services.samples" xmlns:xsd="http://services.samples/xsd"> <soapenv:Header/> <soapenv:Body> <ser:getQuote> <!--Optional:--> <ser:request> <!--Optional:--> <xsd:symbol>IBM</xsd:symbol> </ser:request> </ser:getQuote> </soapenv:Body> </soapenv:Envelope>
The message will be logged in ESB console. SOAP UI will get 202 Accepted message, and in the axis2Server console, the following message will be logged.
samples.services.SimpleStockQuoteService :: Generating quote for : IBM
To adapt to your specific environment, simply replace the following with a suitable name.
<endpoint name="SimpleStockQuoteService"> <address uri="http://test"/> </endpoint>