All docs This doc
Skip to end of metadata
Go to start of metadata

This section explains, through an example scenario, how the Message Broker EIP can be implemented using WSO2 ESB. The following topics are covered:

Introduction to Message Broker

The Message Broker EIP decouples the destination of a message from the sender and maintains central control over the flow of messages. It receives messages from multiple destinations, determines the correct destination, and routes the message to the correct channel. The Message Broker EIP decouples messages from senders and receivers. For more information, refer to http://www.eaipatterns.com/MessageBroker.html.

Figure 1: Message Broker EIP

Example scenario

This example scenario demonstrates how WSO2 ESB works with WSO2 Message Broker to implement the Message Broker EIP. In this scenario, sent messages are put into a Message Broker queue, which any interested receiver can consume. If you want to add more receivers, you can use topics in WSO2 Message Broker in a similar manner discussed here.

Environment setup

Setting up WSO2 Message Broker
  1. Start Message Broker profile by executing the following script: <EI_HOME>/wso2/broker/bin/wso2server.sh
Setting up WSO2 ESB
  1. Download and install WSO2 ESB from  http://wso2.com/products/enterprise-service-bus . Installation home will be referred to as <ESB_HOME>. For a list of prerequisites and step-by-step installation instructions, refer to  Installation Guide in the WSO2 ESB documentation.
  2. Copy the following files from <EI_HOME>/wso2/broker/client-lib to <EI_HOME>/repository/components/lib.
    • geronimo-jms_1.1_spec-1.1.0.wso2v1.jar
    • andes-client-0.13.wso2v8.1.jar
  3. Enable the JMS transport receivers and senders by uncommenting the relevant sections in the <ESB_HOME>/repository/conf/axis2/axis2.xml file. For example:

    <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>
    .........
    
    
    <transportSender name="jms" class="org.apache.axis2.transport.jms.JMSSender"/>
  4. Define the following properties in the <ESB_HOME>/repository/conf/jndi.properties file.

    .....
    #Need change QueueConnection factory as follows
    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.myqueue=myqueue
    
    # register some topics in JNDI using the form - Commented since this sample is not going to use Topics
    # topic.[jndiName] = [physicalName]
    #topic.MyTopic = example.MyTopic


    Port should be 5675 for EI with MB profile. Default port is 5672 and MB profile runs with a port offset of 3.
    You do not need Axis2 server for this example scenario. You do not view a response in StockQuote client.
    ESB Console output: 

    INFO - LogMediator To: , WSAction: "urn:getQuote", SOAPAction: "urn:getQuote", MessageID: ID:8f192fb7-c90b-369e-b2af-4db9d38bc041, Direction: request, Subscriber = I am Subscribed to messages coming to StockQuoteProxy., Envelope: <?xml version='1.0' encoding='utf-8'?><soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"><soapenv:Body><soapenv:Envelope><soapenv:Body><m0:getQuote xmlns:m0="http://services.samples"><m0:request><m0:symbol>WSO2</m0:symbol></m0:request></m0:getQuote></soapenv:Body></soapenv:Envelope></soapenv:Body></soapenv:Envelope>

ESB configuration

Start the ESB server and log into its management console UI (https: //localhost:9443/carbon ). In the management console,  navigate to the Main menu and click Source View in the Service Bus section . Next, copy and paste the following configuration, which helps you explore the example scenario, to the source view.  

<definitions xmlns="http://ws.apache.org/ns/synapse">
<proxy xmlns="http://ws.apache.org/ns/synapse" name="StockQuoteProxy" transports="http https" startOnLoad="true">
    <description/>
    <target>
        <inSequence>
            <property name="OUT_ONLY" value="true"/>
            <property name="FORCE_SC_ACCEPTED" value="true" scope="axis2"/>
            <property name="transport.jms.ContentTypeProperty" value="Content-Type" scope="axis2"/>
            <send>
                <endpoint>
                    <address uri="jms:/myqueue?transport.jms.ConnectionFactoryJNDIName=QueueConnectionFactory&amp;java.naming.factory.initial=org.wso2.andes.jndi.PropertiesFileInitialContextFactory&amp;java.naming.provider.url=conf/jndi.properties&amp;transport.jms.DestinationType=queue"/>
                </endpoint>
            </send>
        </inSequence>
        <outSequence>
            <property name="TRANSPORT_HEADERS" scope="axis2" action="remove"/>
            <send/>
        </outSequence>
    </target>
</proxy>
<proxy xmlns="http://ws.apache.org/ns/synapse" name="StockQuoteProxyConsumer" transports="jms" startOnLoad="true">
    <description/>
    <target>
        <inSequence>
            <property name="OUT_ONLY" value="true"/>
            <log level="full">
                <property name="Subscriber" value="I am Subscribed to messages coming to StockQuoteProxy."/>
            </log>
            <drop/>
        </inSequence>
        <outSequence>
            <send/>
        </outSequence>
    </target>
    <parameter name="transport.jms.DestinationType">queue</parameter>
    <parameter name="transport.jms.Destination">myqueue</parameter>
    <parameter name="transport.jms.ContentType">
        <rules xmlns="">
            <jmsProperty>contentType</jmsProperty>
            <default>application/xml</default>
        </rules>
    </parameter>
    <parameter name="transport.jms.ConnectionFactory">myQueueConnectionFactory</parameter>
</proxy>
</definitions>



Simulating the sample scenario

Send a request using Stock Quote client to the proxy service in the following manner. For information on the Stock Quote client, refer to the Sample Clients section in WSO2 ESB documentation. 

ant stockquote -Dtrpurl=http://localhost:8280/services/StockQuoteProxy -Dsymbol=WSO2

You will not view a response in 

Note that the request is stored in WSO2 Message Broker. Any consumer can access the stored message by accessing  destinationMyQueue in WSO2 Message Broker.

How the implementation works

Let's investigate the elements of the ESB configuration in detail. The line numbers below are mapped with the ESB configuration shown above.

  • Proxy service [line 3 in ESB config] - Defines a proxy service named StockQuoteProxy.
  • endoint [line 10 in ESB config] - Defines an endpoint inside the proxy service. The address of the endpoint is a JMS URL. The JMS URL is made up of the following elements:
  • jms:/myqueue - Looks for a JNDI entry myqueue (see JNDI properties above).
  • ? - Separator indicating extra attributes.
  • transport.jms.ConnectionFactoryJNDIName=QueueConnectionFactory - Looks up ConnectionFactory in JNDI with name QueueConnectionFactory.
  • &amp;  - Separator (this will convert to ‘&’)
  • java.naming.factory.initial=org.wso2.andes.jndi.PropertiesFileInitialContextFactory -  Uses the andes properties-based JNDI.
  • &amp;  - Another separator (this will convert to ‘&’)
  • java.naming.provider.url=repository/conf/jndi.properties -  Looks in  repository/conf/jndi.properties for the JNDI properties file.
  • No labels