[英]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版本中對此進行了測試。)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.