| <?xml version="1.0" encoding="ISO-8859-1" ?> |
| <!-- |
| ~ Licensed to the Apache Software Foundation (ASF) under one |
| ~ or more contributor license agreements. See the NOTICE file |
| ~ distributed with this work for additional information |
| ~ regarding copyright ownership. The ASF 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. |
| --> |
| |
| <document> |
| <properties> |
| <title>Apache Synapse - Sample 420</title> |
| </properties> |
| <body> |
| <section name="Sample 420: Simple Response Caching Scenario"> |
| <div class="xmlConf"><definitions xmlns="http://ws.apache.org/ns/synapse"> |
| |
| <sequence name="main"> |
| <in> |
| <cache timeout="20" scope="per-host" collector="false" |
| hashGenerator="org.wso2.caching.digest.DOMHASHGenerator"> |
| <implementation type="memory" maxSize="100"/> |
| </cache> |
| <send> |
| <endpoint> |
| <address uri="http://localhost:9000/services/SimpleStockQuoteService"/> |
| </endpoint> |
| </send> |
| </in> |
| <out> |
| <cache collector="true"/> |
| <send/> |
| </out> |
| </sequence> |
| |
| </definitions></div> |
| <subsection name="Objective"> |
| <p> |
| Showcase the caching capabilities of Synapse by implementing a simple response |
| cache in Synapse for an actual service deployed on Axis2 |
| </p> |
| </subsection> |
| <subsection name="Pre-requisites"> |
| <p> |
| <ul> |
| <li> |
| Deploy the SimpleStockQuoteService in the sample Axis2 server and start Axis2 |
| </li> |
| <li> |
| Start Synapse using the configuration numbered 420 (repository/conf/sample/synapse_sample_420.xml) |
| <div class="command"> |
| Unix/Linux: sh synapse.sh -sample 420<br/> |
| Windows: synapse.bat -sample 420 |
| </div> |
| </li> |
| </ul> |
| </p> |
| </subsection> |
| <subsection name="Executing the Client"> |
| <p> |
| In this sample, the message sent to Synapse is checked for an existing cached |
| response by calculating the hash value of the request. If there is a cache hit |
| in Synapse, then this request will not be forwarded to the actual service. Rather, |
| Synapse responds to the client with the cached response. In case of a cache miss |
| that particular message will be forwarded to the actual service and caches that |
| response in the out path for the use of consecutive requests of the same type. |
| </p> |
| <p> |
| To try out this scenario, send a request from the sample client as follows. |
| </p> |
| <div class="command">ant stockquote -Dtrpurl=http://localhost:8280/</div> |
| <p> |
| You will notice that if you send more than one requests within 20 seconds, only |
| the first request is forwarded to the actual service, and the rest of the requests |
| will be served by the cache inside Synapse. You could observe this by looking at |
| the logs printed by the Axis2 server, as well as by observing a constant quote value in |
| the response to the client instead of the random rate, which changes by each and |
| every 20 seconds. |
| </p> |
| </subsection> |
| </section> |
| <p><a href="../samples.html">Back to Catalog</a></p> |
| </body> |
| </document> |