<?xml version="1.0" encoding="ISO-8859-1"?>
<!--
  ~  Copyright (c) 2009, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
  ~
  ~  WSO2 Inc. licenses this file to you under the Apache License,
  ~  Version 2.0 (the "License"); you may not use this file except
  ~  in compliance with the License.
  ~  You may obtain a copy of the License at
  ~
  ~    http://www.apache.org/licenses/LICENSE-2.0
  ~
  ~  Unless required by applicable law or agreed to in writing,
  ~  software distributed under the License is distributed on an
  ~  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  ~  KIND, either express or implied.  See the License for the
  ~  specific language governing permissions and limitations
  ~  under the License.
  -->

<!DOCTYPE html
     PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
     "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
  <meta content="text/html; charset=iso-8859-1" http-equiv="content-type"/>
  <title>WSO2 ESB - Store and Forward Messaging patterns with Message Stores and Message Processors </title>
</head>

<body>
<h1>Store and Forward Messaging patterns with Message Stores and Message Processors</h1>
    <p>
        Message Stores and Message Processors can be used to implement different store
        and forward messaging patterns.
        This can be use to cater different SLA s and other QoS aspects.
    </p>
     <h2>
            <a name="Sample700">Sample 700: Introduction to Message Store</a></h2>
        <pre xml:space="preserve">
            &lt;!-- Introduction to the  Message Store --&gt;
            &lt;definitions xmlns="http://ws.apache.org/ns/synapse"&gt;
            &lt;sequence name="fault"&gt;
            &lt;log level="full"&gt;
            &lt;property name="MESSAGE" value="Executing default 'fault' sequence"/&gt;
            &lt;property name="ERROR_CODE" expression="get-property('ERROR_CODE')"/&gt;
            &lt;property name="ERROR_MESSAGE" expression="get-property('ERROR_MESSAGE')"/&gt;
            &lt;/log&gt;
            &lt;drop/&gt;
            &lt;/sequence&gt;
            &lt;sequence name="onStoreSequence"&gt;
            &lt;log&gt;
            &lt;property name="On-Store" value="Storing message"/&gt;
            &lt;/log&gt;
            &lt;/sequence&gt;
            &lt;sequence name="main"&gt;
            &lt;in&gt;
            &lt;log level="full"/&gt;
            &lt;property name="FORCE_SC_ACCEPTED" value="true" scope="axis2"/&gt;
            &lt;store messageStore="MyStore" sequence="onStoreSequence"/&gt;
            &lt;/in&gt;
            &lt;description&gt;The main sequence for the message mediation&lt;/description&gt;
            &lt;/sequence&gt;
            &lt;messageStore name="MyStore"/&gt;
            &lt;/definitions&gt;
        </pre>
    <p>
    <strong>Objective: </strong>Introduction to Message Stores</p>
    <p><strong>Prerequisites</strong>:
        <br/>Start the configuration numbered 700: i.e. wso2esb-samples -sn 700
    </p>
    <p>To Execute the Client : </p>
    <pre xml:space="preserve">ant stockquote -Daddurl=http://localhost:9000/services/SimpleStockQuoteService -Dtrpurl=http://localhost:8280/ -Dmode=placeorder
    </pre>
    <p>When you execute the client the message will be dispatched to the main sequence.
        In the Main sequence store mediator will store the placeOrder request message in the "MyStore" Message Store</p>

        <p>Before Storing the message store mediator will invoke the sequence :onStoreSequence. See the log</p>
        <p>INFO - LogMediator To: http://localhost:9000/services/SimpleStockQuoteService, WSAction: urn:placeOrder, SOAPAction: urn:placeOrder, ReplyTo: http://www.w3.org/2005/08/addressing/none, MessageID: urn:uuid:54f0e7c6-7b43-437c-837e-a825d819688c, Direction: request, On-Store = Storing message
        </p>


    <p>You can then use the JMX view of Synapse Message Store by using the jconsole and view the stored
        Messages and delete them.
    </p>
            <h2>
    <a name="Sample701">Sample 701: Introduction to Message Sampling Processor</a></h2>
        <pre xml:space="preserve">
            &lt;!-- Introduction to  Message Sampling Processor --&gt;

            &lt;definitions xmlns="http://ws.apache.org/ns/synapse"&gt;

            &lt;sequence name="send_seq"&gt;
            &lt;send&gt;
            &lt;endpoint&gt;
            &lt;address uri="http://localhost:9000/services/SimpleStockQuoteService"&gt;
            &lt;suspendOnFailure&gt;
            &lt;errorCodes&gt;-1&lt;/errorCodes&gt;
            &lt;progressionFactor&gt;1.0&lt;/progressionFactor&gt;
            &lt;/suspendOnFailure&gt;
            &lt;/address&gt;
            &lt;/endpoint&gt;
            &lt;/send&gt;
            &lt;/sequence&gt;
            &lt;sequence name="main"&gt;
            &lt;in&gt;
            &lt;log level="full"/&gt;
            &lt;property name="FORCE_SC_ACCEPTED" value="true" scope="axis2"/&gt;
            &lt;property name="OUT_ONLY" value="true"/&gt;
            &lt;store messageStore="MyStore"/&gt;
            &lt;/in&gt;
            &lt;description&gt;The main sequence for the message mediation&lt;/description&gt;
            &lt;/sequence&gt;
            &lt;messageStore name="MyStore"/&gt;
            &lt;messageProcessor
            class="org.apache.synapse.message.processors.sampler.SamplingProcessor"
            name="SamplingProcessor" messageStore="MyStore"&gt;
            &lt;parameter name="interval"&gt;20000&lt;/parameter&gt;
            &lt;parameter name="sequence"&gt;send_seq&lt;/parameter&gt;
            &lt;/messageProcessor&gt;
            &lt;/definitions&gt;
        </pre>
        <p>
            <strong>Objective:</strong>Introduction to Message Sampling Processor
        </p>
        <p><strong>Prerequisites</strong>:
        <br/>Start the configuration numbered 701: i.e. wso2esb-samples -sn 701 </p>
        <p>Start the SimpleStockQuoteService if its not already started</p>
        <p>To Execute the Client few times:</p>
        <pre xml:space="preserve">ant stockquote
            -Daddurl=http://localhost:9000/services/SimpleStockQuoteService
            -Dtrpurl=http://localhost:8280/ -Dmode=placeorder
        </pre>
        <p>When you execute the client the message will be dispatched to the main sequence.
            In the Main sequence store mediator will store the placeOrder request message in the
            "MyStore" Message Store
        </p>

        <p>Message Processor will consume the messages and forward to the send_seq sequence in
            configured rate.
        </p>
        <p>You will observe that service invocation rate is not changing when increasing the rate we
            execute the client.
        </p>
    <h2>
    <a name="Sample702">Sample 702: Introduction to Message Forwarding Processor</a></h2>
        <pre xml:space="preserve">

            &lt;!-- Introduction to Scheduled Message Forwarding Processor --&gt;

            &lt;definitions xmlns="http://ws.apache.org/ns/synapse"&gt;

            &lt;endpoint name="StockQuoteServiceEp"&gt;
            &lt;address uri="http://localhost:9000/services/SimpleStockQuoteService"&gt;
            &lt;suspendOnFailure&gt;
            &lt;errorCodes&gt;-1&lt;/errorCodes&gt;
            &lt;progressionFactor&gt;1.0&lt;/progressionFactor&gt;
            &lt;/suspendOnFailure&gt;
            &lt;/address&gt;
            &lt;/endpoint&gt;
            &lt;sequence name="fault"&gt;
            &lt;log level="full"&gt;
            &lt;property name="MESSAGE" value="Executing default 'fault' sequence"/&gt;
            &lt;property name="ERROR_CODE" expression="get-property('ERROR_CODE')"/&gt;
            &lt;property name="ERROR_MESSAGE" expression="get-property('ERROR_MESSAGE')"/&gt;
            &lt;/log&gt;
            &lt;drop/&gt;
            &lt;/sequence&gt;
            &lt;sequence name="main"&gt;
            &lt;in&gt;
            &lt;log level="full"/&gt;
            &lt;property name="FORCE_SC_ACCEPTED" value="true" scope="axis2"/&gt;
            &lt;property name="OUT_ONLY" value="true"/&gt;
            &lt;property name="target.endpoint" value="StockQuoteServiceEp"/&gt;
            &lt;store messageStore="MyStore"/&gt;
            &lt;/in&gt;
            &lt;description&gt;The main sequence for the message mediation&lt;/description&gt;
            &lt;/sequence&gt;
            &lt;messageStore name="MyStore"/&gt;
            &lt;messageProcessor
            class="org.apache.synapse.message.processors.forward.ScheduledMessageForwardingProcessor"
            name="ScheduledProcessor" messageStore="MyStore"&gt;
            &lt;parameter name="interval"&gt;10000&lt;/parameter&gt;
            &lt;/messageProcessor&gt;
            &lt;/definitions&gt;
        </pre>
    <p>
    <strong>Objective:</strong>Introduction to Message Forwarding Processor</p>
   <p> <strong>Prerequisites</strong>:

    <br/>
    Start the configuration numbered 702: i.e. wso2esb-samples -sn 702 </p>

    <p>To Execute the Client: </p>
    <pre xml:space="preserve">ant stockquote -Daddurl=http://localhost:9000/services/SimpleStockQuoteService -Dtrpurl=http://localhost:8280/ -Dmode=placeorder
</pre>

        <p>Now Start the SimpleStockQuoteService</p>
        <p>When you Start the service you will see message getting delivered to the service. Even
            though service is down when we invoke it from the client
        </p>
        <p>Here in the Main sequence store mediator will store the placeOrder request message in the
            "MyStore" Message Store
        </p>
        <p>Message Processor will send the message to the endpoint configured as a message context
            property.
        </p>
        <p>Message processor will remove the message from the store only if message delivered
            successfully
        </p>
</body>
</html>
