【问题标题】:How to resolve Could not serialize object Caused error while using cache scope in mule 4如何解决在 mule 4 中使用缓存范围时无法序列化对象导致错误
【发布时间】:2020-08-08 05:32:41
【问题描述】:

我在我的流程中添加了缓存范围以响应 http 请求。在缓存范围之前,我有一个具有 json 对象的 set-variable 组件,因为我遇到了错误。当我删除 设置变量它正在工作。即使我使用 set-variable,我该如何解决这个问题?

错误:

 com.mulesoft.mule.runtime.cache.internal.ObjectStoreCachingStrategy: Unable to store event in cache
 org.mule.runtime.api.store.ObjectStoreException: Could not serialize object Caused by: 
 org.mule.runtime.api.serialization.SerializationException: Could not serialize object 

流程:

<flow name="tokenFlow" doc:id="cb6d9de3-45fa-47f0-b2f5-875048d0b980" ><http:listener doc:name="Listener" doc:id="36c16957-47c1-4d07-b6c2-694e6c86a9f3" config-ref="HTTP_Listener_config" path="/fssvc-api/collectionSFDCInbound"/>
    <set-variable value="#[payload]" doc:name="Set Variable" doc:id="3f372591-b02a-4d82-a634-159b865090ca" variableName="request" />
    <ee:cache doc:name="Cache" doc:id="ae4c75b2-5e92-4578-9966-1277b47b472a" cachingStrategy-ref="Caching_Strategy1">
        <http:request method="POST" doc:name="Request" doc:id="08d40c87-8f60-4b4e-8e20-1c93c1b52477" config-ref="HTTP_Request_configuration" url="https://idfcfirstbank--colqaorg.my.salesforce.com/services/oauth2/token?">
        <http:query-params><![CDATA[#[output
  application/java
   ---
 {
"password" : "test",
"grant_type" : "password",
"client_secret" : "test1234",
"client_id" : "1234",
"username" : "test@gmail.com"
}]]]></http:query-params>
    </http:request>
    </ee:cache>
</flow>

【问题讨论】:

    标签: mule mule-component mulesoft mule4


    【解决方案1】:

    知识库文章https://help.mulesoft.com/s/article/Mule-4-flow-variable-causing-ObjectStoreException中描述了该问题

    正如它所解释的,您可以将变量转换为字符串以避免序列化问题。

    例子:

    <set-variable value="#[output application/java --- payload as String]" ...>
    

    自 Mule 4.3.0 以来,存储在缓存中的信息范围已经缩小,因此将 Mule 版本迁移到上一个版本是一种解决方案。

    【讨论】:

    • 嗨 @aled 我在使用这种方法时遇到的一个问题是 long 值正在转换为 double 我可以避免这种情况吗?
    • 你应该为此提出一个新问题。
    • 我也面临同样的问题。并且知识库文章没有提出明确的解决方案(这是一个猜谜游戏)
    • 根据我最近的经验,mulesoft 支持在 4.3 运行时解决了这个问题(获得了我的运行时 4.2.2 的补丁)。它对我有用
    • 我最近遇到过这种情况,当时我试图缓存通过 Web 服务使用者连接器调用 SOAP Web 服务的结果。问题似乎是缓存处理器想要缓存完整的消息,而不仅仅是即将返回的有效负载 - 并且消息对象的属性被消费者设置为 SoapAttributes 的实例,这是不可序列化的。我还没有找到解决方法,但是:-(。这是使用 Mule 4.4 EE 运行时。
    【解决方案2】:

    我的场景有点复杂,因为我的问题是,当我想将消息序列化到缓存时,它已经被 SOAP 调用的结果替换了 - 并且替换了具有 SoapAttributes 实例的消息的 attributes 属性,该实例不是 Java 可序列化的。 对我有用的解决方案是让我的 Mule 应用程序使用 Kryo 序列化程序,而不关心要保存的对象是否是可序列化的。 我的配置中的两个条目是:

       <kryo:serializer name="kryo" compressionMode="GZIP" />
       <configuration defaultObjectSerializer-ref="kryo" />
    

    你可以阅读它here

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-08-16
      • 2015-04-27
      • 1970-01-01
      相关资源
      最近更新 更多