Over a million developers have joined DZone.
{{announcement.body}}
{{announcement.title}}

WSO2 ESB Cache Mediator Tutorial

DZone's Guide to

WSO2 ESB Cache Mediator Tutorial

· Integration Zone ·
Free Resource

SnapLogic is the leading self-service enterprise-grade integration platform. Download the 2018 GartnerMagic Quadrant for Enterprise iPaaS or play around on the platform, risk free, for 30 days.

This 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”

image

  • 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

image

Out Sequence

image

4. Try it out

image

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 

image

image

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.




With SnapLogic’s integration platform you can save millions of dollars, increase integrator productivity by 5X, and reduce integration time to value by 90%. Sign up for our risk-free 30-day trial!

Topics:

Published at DZone with permission of

Opinions expressed by DZone contributors are their own.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}