Mule Caching Strategy using Redis -


i'm looking way have shared cache across 2 servers , investigating using redis object-store-caching-strategy encountering problem when reading stored values.

it stores value when cache hit miss value throws error when retrieving value.

the required object/property "mulecontext" null

at guess seems object-store-caching-strategy might need object store implements mulecontextaware interface.

does know if correct or how resolve issue?

here example flow

    <mule xmlns:redis="http://www.mulesoft.org/schema/mule/redis" xmlns:ee="http://www.mulesoft.org/schema/mule/ee/core"     xmlns:http="http://www.mulesoft.org/schema/mule/http" xmlns="http://www.mulesoft.org/schema/mule/core" xmlns:doc="http://www.mulesoft.org/schema/mule/documentation" xmlns:spring="http://www.springframework.org/schema/beans" version="ee-3.4.0" xmlns:xsi="http://www.w3.org/2001/xmlschema-instance" xsi:schemalocation="http://www.mulesoft.org/schema/mule/ee/core http://www.mulesoft.org/schema/mule/ee/core/current/mule-ee.xsd http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-current.xsd http://www.mulesoft.org/schema/mule/core http://www.mulesoft.org/schema/mule/core/current/mule.xsd http://www.mulesoft.org/schema/mule/http http://www.mulesoft.org/schema/mule/http/current/mule-http.xsd http://www.mulesoft.org/schema/mule/redis http://www.mulesoft.org/schema/mule/redis/3.4/mule-redis.xsd">       <redis:config name="redis" doc:name="redis" defaultpartitionname="test" />     <ee:object-store-caching-strategy name="redis_caching_strategy" doc:name="caching strategy">         <spring-object-store ref="redis" />     </ee:object-store-caching-strategy>      <flow name="htmlcacheredisflow" doc:name="htmlcacheredisflow">         <http:inbound-endpoint exchange-pattern="request-response" host="localhost" port="8084" path="cacheredis" doc:name="http"/>         <expression-transformer expression="#[payload.substring(payload.lastindexof('/') + 1)]" doc:name="expression"/>         <ee:cache doc:name="cache" cachingstrategy-ref="redis_caching_strategy" >             <logger message="getting item db key #[payload]" level="info" doc:name="logger"/>             <expression-transformer expression="#[payload + 'asd']" doc:name="expression"/>         </ee:cache>     </flow>  </mule> 

as noted david, in question comments, ee cache scope not available in community edition. there ways implement caching in community edition.

the blog post enterprise caching mule esb community edition shows how can adding custom interceptor. blog post uses ehcache modify example use redis instead.

the blog post in short is:

<custom-interceptor doc:name="payloadcache"         class="se.redpill.mulecomponents.cache.payloadcache">      <spring:property name="cache" ref="mycache"/>   </custom-interceptor> 

and payloadcache.java

package se.redpill.mulecomponents.cache;   import net.sf.ehcache.ehcache;   import net.sf.ehcache.element;   import org.mule.defaultmuleevent;   import org.mule.defaultmulemessage;   import org.mule.api.muleevent;   import org.mule.api.muleexception;   import org.mule.api.mulemessage;   import org.mule.api.interceptor.interceptor;   import org.mule.api.processor.messageprocessor;   /**    * mule interceptor acting ehcache component.    * based on cache interceptor blueprint mule in action david dossot , john d'emic,    *     */   public class payloadcache implements interceptor    {               private messageprocessor next;          private ehcache cache;          public void setlistener(messageprocessor listener)          {            next = listener;          }          public void setcache(final ehcache cache)          {            this.cache = cache;          }          public muleevent process(muleevent event) throws muleexception          {            final mulemessage currentmessage = event.getmessage();            final object key = currentmessage.getpayload();            final element cachedelement = cache.get(key);            if (cachedelement != null)            {              return new defaultmuleevent(new defaultmulemessage(cachedelement.getobjectvalue(),                currentmessage, event.getmulecontext()), event);            }            final muleevent result = next.process(event);            cache.put(new element(key, result.getmessage().getpayload()));            return result;          }   }   

Comments

Popular posts from this blog

java.util.scanner - How to read and add only numbers to array from a text file -

rewrite - Trouble with Wordpress multiple custom querystrings -