WSO2 ESB Cache Mediator Tutorial
Join the DZone community and get the full member experience.
Join For FreeThis tutorial is about Caching Responses Over Requests. It means when WSO2 ESB gets the same request then Cache Mediator will send out Caching Responses. In this example I am using my last service that I created from WSO2 DSS.
1. Start DSS (With my last Services/ or any service you wish to used – remote Services) and WSO2 ESB.
2. Create “Pass Through Proxy”
- Cache Id: Same id for a cache mediator instance in incoming path and the corresponding mediator instance in outgoing message path.
- Cache Scope: This is important if the service is deployed in a cluster.
Per-Host: current host in a cluster.
Per-Mediator: Twhole cluster. - Cache Type: Whether the mediator is in the incoming path (check request) or the outgoing path (cache the response).
- Finder: Set if the message is incoming path. This indicate the mediator find for the request hash of each incoming message.
- Collector: Set if the message is in outgoing path. This indicate the mediator collect the response message in the cache.
- Hash Generator: The logic for finding each incoming message.
- Cache Timeout: expiring time (seconds).
- Maximum Message Size: The limit of the message to cache in bytes.
- Implementation Type: Currently only "In-Memory" is available.
- On Cache Hit: Specify the sequence to follow when the cache mediator is hit. (named sequence of mediators from the registry.)
3. Now add Cache mediator to the proxy.
In Sequence
Out Sequence
4. Try it out
5. Now testing is it coming from cache or not proxy level login
6. Here is my new proxy with logs
<proxy xmlns="http://ws.apache.org/ns/synapse" name="TestingCacheProxy" transports="https,http" statistics="disable" trace="disable" startOnLoad="true"> <target> <inSequence> <log> <property name="testing" value="Request arrives in to InSequence"/> </log> <cache scope="per-host" collector="false" hashGenerator="org.wso2.caching.digest.DOMHASHGenerator" timeout="20" maxMessageSize="500"> <implementation type="memory" maxSize="1000"/> </cache> <log> <property name="testing" value="Hi, I am after Cache"/> </log> <send> <endpoint> <address uri="http://localhost:9764/services/PostgresDataService?wsdl"/> </endpoint> </send> </inSequence> <outSequence> <log> <property name="testing" value="Hi, I in the top of Out Sequence"/> </log> <cache scope="per-host" collector="true"/> <log> <property name="testing" value="I am in Out Sequence and below the Cache"/> </log> <send/> </outSequence> </target> <publishWSDL uri="http://localhost:9764/services/PostgresDataService?wsdl"/> <description></description> </proxy>
Now call some, and see
Read line mapping Show the 1st call,
Blue Line shows next call that was respond from cache .
Cache will speed up you systems/proxies. So it is time to use it.
Published at DZone with permission of Madhuka Udantha, DZone MVB. See the original article here.
Opinions expressed by DZone contributors are their own.
Comments