简体   繁体   中英

Using DataWeave in Mule cache

Two months ago, I had configured an EE cache in Mulesoft. All of a sudden, it stopped working. It turned out that DataWeave cannot be placed inside the cache scope. Once I move it out of the scope, it works perfectly again. I tested with this :

<set-payload value="#[message.inboundProperties.'http.request.uri']" doc:name="Set Payload"/>
        <ee:cache cachingStrategy-ref="EBX_Response_Caching_Strategy" doc:name="Cache">
            <logger message="No entry with key: '#[payload]' was found in the cache. A request will be send to EBX service. Detailed response is returned: #[flowVars.detailedResponse]" level="INFO" doc:name="Logger"/>
            <scripting:transformer encoding="UTF-8" mimeType="application/json" doc:name="Set filter">
                <scripting:script engine="Groovy"><![CDATA[
flowVars['filter'] = 'filtervalue' ]]></scripting:script>
            </scripting:transformer>
            <http:request config-ref="HTTP_Request_Configuration" path="/ebx-dataservices/rest/data/v1/" method="GET" doc:name="EBX HTTP call">
                <http:request-builder>
                    <http:query-param paramName="login" value="${svc0031.login}"/>
                    <http:query-param paramName="password" value="${svc0031.password}"/>
                    <http:query-param paramName="pageSize" value="unbounded"/>
                    <http:query-param paramName="filter" value="#[filter]"/>
                    <http:header headerName="Host" value="myhost.com"/>
                </http:request-builder>
            </http:request>

            </ee:cache>
        <dw:transform-message metadata:id="91c16073-669d-4c27-a3ea-5cbae4e56ede" doc:name="Basic info response">
            <dw:input-payload doc:sample="sample_data\json.json"/>
            <dw:set-payload><![CDATA[%dw 1.0
%output application/json
---
{
    hotels: payload.rows map ((row , indexOfRow) -> {
        name: row.content.companyName.content,
        propertyCode: row.content.propertyCode.content,
    })
}]]></dw:set-payload>
        </dw:transform-message>

If I move the DataWeave transformation in the cache scope, the caching just stops working and a request is sent to the backendsystem always. Why is that? Did MuleSoft change something? We are running on ESB 3.7.3

You are using a consumable payload in Cache Scope and when we use Consumable payload then Cache is always a MISS and your processors inside the Cache scope will process again even after the Cache is used. In your case, you are using a HTTP requester which will give you a Consumable response and therefore Cache strategy is being abandoned. Solution is use a 'Byte Array to Object' to Consume the stream and make the response Non-consumable so that the Cache will cache it in memory and next time it will be a Cache-HIT and it will pick up from In-memory Cache. Other option for you is to use Dataweave inside the Cache Scope, that will also consume your incoming stream and make Cache a HIT.

For more info on Cache HIT and MISS and Consumable responses go here : https://docs.mulesoft.com/mule-user-guide/v/3.7/cache-scope

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM