Mule 4仅有效负载缓存响应生成器

时间:2019-05-22 22:55:42

标签: caching mulesoft mule4

在Mule 3.x中,我们使用了缓存策略,该策略使用仅有效负载生成器来缓存有效负载,而不是使用本指南中找到的类来缓存整个有效负载

https://support.mulesoft.com/s/article/How-to-cache-only-the-payload-and-not-the-entire-message

package com.mulesoft.support;



import org.mule.DefaultMuleEvent;
import org.mule.api.MuleEvent;

import com.mulesoft.mule.cache.responsegenerator.ResponseGenerator;

public class PayloadResponseGenerator implements ResponseGenerator
{
  @Override
  public MuleEvent create(MuleEvent request, MuleEvent cachedResponse)
  {
    // we only need to set the payload
    request.getMessage().setPayload(cachedResponse.getMessage().getPayload());

    return request;
  }
}

我正在尝试在m子4中实现它,但在新的api事件接口上找不到等效的setPayload

import org.mule.api.MuleEvent;

import org.mule.runtime.core.api.event.CoreEvent;

import com.mulesoft.mule.runtime.cache.api.response.ResponseGenerator;

public class PayloadOnlyCachingResponseGenerator implements ResponseGenerator{

    @Override
    public MuleEvent create(MuleEvent requestedEvent, MuleEvent cachedResponseEvent) {

        Object cachedPayload = cachedResponseEvent.getMessage().getPayload();

        requestedEvent.getMessage().setPayload(cachedPayload);

        return requestedEvent;
    }

}

设置有效负载时出现错误,因为它不再存在。我们还有另一种方法可以实现吗?

预先感谢

0 个答案:

没有答案