2016-02-02 85 views
0

我在wso2 esb中创建了一个API来调用其余服务。我已经使用了缓存介体,它对于正常的GET方法工作正常。Cache Mediator wso2 esb api

我想要的是,我用GET方法获取员工详细信息,我将通过url传递employee_id。

这个API调用是第一次为给定的employee_id创建服务,然后为了下一次调用同一个employee_id,它应该从缓存本身获得响应,直到给定的Timeout时间段。如果我更改employee_id,那么它应该打到服务,但它从缓存中获得响应。对于不同的employee_id也是如此。

我的API是,

<api xmlns="http://ws.apache.org/ns/synapse" name="cacheApi" context="/cacheApi"> 
<resource methods="GET" uri-template="/{id}/"> 
    <inSequence> 
    <log/> 
    <cache id="" scope="per-host" collector="false" hashGenerator="org.wso2.carbon.mediator.cache.digest.DOMHASHGenerator" timeout="60"> 
     <implementation type="memory" maxSize="10"/> 
    </cache> 
    <send> 
     <endpoint> 
      <http method="GET" uri-template="http://localhost:8080/rest-services/services/employee/{uri.var.id}"/> 
     </endpoint> 
    </send> 
    </inSequence> 
    <outSequence> 
    <cache scope="per-host" collector="true"/> 
    <send/> 
    </outSequence> 
</resource> 
</api> 

我的API调用会作为,

http://localhost:8280/cacheApi/1 
http://localhost:8280/cacheApi/2 
http://localhost:8280/cacheApi/3 
.... 

谁能帮我解决这个?

在此先感谢

回答

0

你需要实现自己的散列发生器,因为org.wso2.carbon.mediator.cache.digest.DOMHASHGenerator散列仅基于请求/ msgContext.getEnvelope().getBody()的身体(实现org.wso2.carbon.mediator.cache.digest.DigestGenerator),并不会为你的API工作。

0

有一个你可以尝试的哈希生成器的新实现,它使用API​​ URI来生成哈希值。

为了应用它,请将散列生成器设置为org.wso2.carbon.mediator.cache.digest.REQUESTHASHGenerator

现在缓存调解员应该像现在这样,

<cache id="" scope="per-host" collector="false" hashGenerator="org.wso2.carbon.mediator.cache.digest.REQUESTHASHGenerator" timeout="60"> 
     <implementation type="memory" maxSize="10"/> 
</cache> 

(PS:我只测试了本作的WSO2 ESB 4.9.0版本)