Cache Mediator wso2 esb api



我在 wso2 esb 中创建了一个 API 来调用 rest-service。我使用了缓存调解器,它适用于正常的GET方法。

想要的是,我使用了GET方法来获取员工详细信息,我将传递带有 url 的employee_id。

对于给定employee_id,此 API 调用首次命中服务,然后对于同一employee_id的下一次调用,它应该在给定的超时期限内从缓存本身获取响应。 如果我更改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
....

谁能帮我解决这个问题??

提前致谢

您需要

实现自己的哈希生成器(实现org.wso2.carbon.mediator.cache.digest.DigestGenerator),因为org.wso2.carbon.mediator.cache.digest.DOMHASHGenerator哈希仅基于请求/msgContext.getEnvelope().getBody()的正文,不适用于您的API。

您可以尝试哈希生成器的新实现,它也使用 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版本中测试过这个。

最新更新