Skip to content

Using the Message Sampling Processor

This example demonstrates the usage of the message sampling processor.

Synapse configuration

Following are the artifact configurations that we can use to implement this scenario. See the instructions on how to build and run this example.

<sequence xmlns="http://ws.apache.org/ns/synapse" name="send_seq">
    <send>
        <endpoint>
            <address uri="http://localhost:9000/services/SimpleStockQuoteService">
                <suspendOnFailure>
                <errorCodes>-1</errorCodes>
                <progressionFactor>1.0</progressionFactor>
                </suspendOnFailure>
            </address>
        </endpoint>
    </send>
</sequence>           
<proxy xmlns="http://ws.apache.org/ns/synapse" name="StockQuoteProxy" transports="https http" startOnLoad="true" trace="disable">
          <description />
    <target>
       <inSequence>
            <log level="full"/>
            <property name="FORCE_SC_ACCEPTED" value="true" scope="axis2"/>
            <property name="OUT_ONLY" value="true"/>
            <store messageStore="MyStore"/>
        </inSequence>
        <outSequence>
             <send />
        </outSequence>
    </target>
</proxy>
<messageStore xmlns="http://ws.apache.org/ns/synapse" name="MyStore"/>
<messageProcessor xmlns="http://ws.apache.org/ns/synapse"
     class="org.apache.synapse.message.processor.impl.sampler.SamplingProcessor"
     name="SamplingProcessor" messageStore="MyStore">
    <parameter name="interval">20000</parameter>
    <parameter name="sequence">send_seq</parameter>
</messageProcessor> 

Build and run

Create the artifacts:

  1. Set up WSO2 Integration Studio.
  2. Create an ESB Solution project.
  3. Create the proxy service, mediation sequences, message store, and message processor with the configurations given above.
  4. Deploy the artifacts in your Micro Integrator.

Configure the ActiveMQ broker and set up the JMS Sender.

Set up the back-end service:

  1. Download the stockquote_service.jar.
  2. Open a terminal, navigate to the location of the downloaded service, and run it using the following command:

    java -jar stockquote_service.jar

Send the following request to invoke the service:

POST http://localhost:9090/services/StockQuoteProxy HTTP/1.1
Accept-Encoding: gzip,deflate
Content-Type: text/xml;charset=UTF-8
SOAPAction: "urn:getQuote"
Content-Length: 492
Host: localhost:9090
Connection: Keep-Alive
User-Agent: Apache-HttpClient/4.1.1 (java 1.5)

<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 xmlns:ser="http://services.samples" xmlns:xsd="http://services.samples/xsd">
         <ser:request>
            <xsd:symbol>IBM</xsd:symbol>
         </ser:request>
      </ser:getQuote>
   </soapenv:Body>
</soapenv:Envelope>

When you send the request, the message will be dispatched to the proxy service. In the proxy service, the store mediator will store the getQuote request message in the "MyStore" message store. The message processor will consume the messages, and forward them to the "send_seq" sequence in configured rate. You will observe that the service invocation rate is not changing when we increase the rate of proxy service invocation.

Top