简体   繁体   English

在Mule缓存中使用DataWeave

[英]Using DataWeave in Mule cache

Two months ago, I had configured an EE cache in Mulesoft. 两个月前,我在Mulesoft中配置了EE缓存。 All of a sudden, it stopped working. 突然,它停止工作了。 It turned out that DataWeave cannot be placed inside the cache scope. 事实证明,DataWeave无法放置在缓存范围内。 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. 如果我在缓存范围内移动DataWeave转换,则缓存将停止工作,并且始终会将请求发送到后端系统。 Why is that? 这是为什么? Did MuleSoft change something? MuleSoft改变了什么吗? We are running on ESB 3.7.3 我们正在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. 您在Cache Scope中使用了消耗性负载,而当我们使用Consumable负载时,Cache始终是MISS,并且即使使用了Cache,Cache范围内的处理器也将再次处理。 In your case, you are using a HTTP requester which will give you a Consumable response and therefore Cache strategy is being abandoned. 在您的情况下,您正在使用HTTP请求程序,该请求程序将为您提供耗材响应,因此将放弃缓存策略。 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. 解决方案是使用“对象的字节数组”来消耗流并将响应设为非消耗,以便高速缓存将其高速缓存在内存中,下一次它将成为高速缓存HIT,并从内存中高速缓存中进行提取。 。 Other option for you is to use Dataweave inside the Cache Scope, that will also consume your incoming stream and make Cache a HIT. 您的另一种选择是在缓存作用域内使用Dataweave,这也将消耗您的传入流并使缓存成为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 有关Cache HIT和MISS以及耗材响应的更多信息,请访问: https : //docs.mulesoft.com/mule-user-guide/v/3.7/cache-scope

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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