This documentation is for WSO2 Enterprise Service Bus version 4.7.0 . View documentation for the latest release.
Skip to end of metadata
Go to start of metadata

Objective: Demonstrate the use of Cache mediator in order to cache the response and use that cached response as the response for an identical xml request.

<definitions xmlns="">
        <cache timeout="20" scope="per-host" collector="false"
            <implementation type="memory" maxSize="100"/>
                <address uri="http://localhost:9000/services/SimpleStockQuoteService"/>
        <cache collector="true"/>



  • Deploy the SimpleStockQuoteService in sample Axis2 server and start it on port 9000.
  • Start ESB with the sample configuration 420 (i.e. wso2esb-samples -sn 420).

In this sample, the message sent to ESB is checked for an existing cached response by calculating the hash value of the request. If there is a cache hit in ESB then this request will not be forwarded to the actual service, rather ESB respond to the client with the cached response. In case of a cache miss that particular message will be forwarded to the actual service and cached that response in the out path for the use of consecutive requests of the same type.

To observe this behavior, invoke the client as follows.

ant stockquote -Dtrpurl=http://localhost:8280/

You could 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 ESB. You could observe this by looking at the printed line of the axis2 server, as well as by observing a constant rate as the response to the client instead of the random rate, which changes by each and every 20 seconds.

Synchronize web service invocation with Callout mediator

The Callout mediator calls the given service URL with the request message which is given by the source attribute, waits for the response and attaches the received response to the destination which is given by the target attribute. Both the source and the target can be a key or an XPath. In the case of the source, this key refers to either a message context property or to a local entry. For the target, this key refers to a message context property only.

  • No labels