This documentation is for WSO2 Enterprise Service Bus version 4.9.0 . View documentation for the latest release.

All docs This doc

Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

  1. If you have not already done so, see Getting Started with WSO2 ESB for details on installing and running WSO2 ESB.
  2. Log in to the management console at https://localhost:9443/carbon/ using admin for the username and password.
  3. Create an event sink in WSO2 ESB by navigating to Configure ->Event Sinks in the management console. Click on Add Event Sink.

    Fill in the details as in the following table:

    FieldValue
    Namedas_event_sink
    Usernameadmin
    Passwordadmin
    Receiver URLtcp://localhost:7612
    Authenticator URLssl://localhost:7712
    Info

    In WSO2 DAS the default thrift port and the authentication port are 7611 and 7711 respectively. Due to the port offset you configured the new ports are 7612 and 7712 as defined above.

  4. Create a REST API by navigating to Main ->APIs in the management console and click on Add API. Fill in the details as in the table below:

    FieldValue
    API NameStockQuoteAPI
    context/stockquote

    Click on Switch to source view.

    In source view, add the following API configuration where the publish mediator uses the created event sink das_event_sink to publish to an event stream named stockquote_stream:

    Code Block
    <api xmlns="http://ws.apache.org/ns/synapse" name="StockQuoteAPI" context="/stockquote">
       <resource methods="GET" uri-template="/view/{symbol}">
           <inSequence>
               <payloadFactory media-type="xml">
                   <format>
                       <m0:getQuote xmlns:m0="http://services.samples">
                           <m0:request>
                               <m0:symbol>$1</m0:symbol>
                           </m0:request>
                       </m0:getQuote>
                   </format>
                   <args>
                       <arg evaluator="xml" expression="get-property('uri.var.symbol')" />
                   </args>
               </payloadFactory>
               <header name="Action" value="urn:getQuote" />
               <publishEvent>
                   <eventSink>das_event_sink</eventSink>
                   <streamName>stockquote_stream</streamName>
                   <streamVersion>1.0.0</streamVersion>
                   <attributes>
                       <meta>
                           <attribute xmlns:ns="http://org.apache.synapse/xsd" name="http_method" type="STRING" defaultValue="" expression="get-property('axis2', 'HTTP_METHOD')" />
                           <attribute xmlns:ns="http://org.apache.synapse/xsd" name="destination" type="STRING" defaultValue="" expression="get-property('To')" />
                       </meta>
                       <correlation>
                           <attribute xmlns:ns="http://org.apache.synapse/xsd" name="date" type="STRING" defaultValue="" expression="get-property('SYSTEM_DATE')" />
                       </correlation>
                       <payload>
                           <attribute xmlns:m0="http://services.samples" name="symbol" type="STRING" defaultValue="" expression="$body/m0:getQuote/m0:request/m0:symbol" />
                           <attribute name="request" type="STRING" defaultValue="" value="getSimpleQuote" />
                       </payload>
                       <arbitrary />
                   </attributes>
               </publishEvent>
               <send>
                   <endpoint>
                       <address uri="http://localhost:9000/services/SimpleStockQuoteService" format="soap12"/>
                   </endpoint>
               </send>
           </inSequence>
           <outSequence>
               <send />
           </outSequence>
       </resource>
    </api>
  5. Deploy the back-end service  SimpleStockQuoteService. For instructions on deploying sample back-end services, see Deploying sample back-end services.

  6. Start the Axis2 server. For instructions on starting the Axis2 server, see Starting the Axis2 server.

    Anchor
    invokeAPI
    invokeAPI

  7. Open a command line terminal and enter the following request to invoke the API you defined above: 

    curl -v http://localhost:8280/stockquote/view/WSO2

    You will see the response from the SimpleStockQuoteService. 

...