Mule:Retrieving 对象存储在 Mule 3.5 的 MEL 中

Mule:Retrieving object store in an MEL in Mule 3.5

需要在选择路由器中测试对象存储是否包含密钥

<objectstore:config name="storeDownload" doc:name="ObjectStore" persistent="false" partition="test"/>

      <choice>
         <when  expression="#[app.registry.storeDownload.contains('#[flowVars.startKey]').equals('false')]">

出现错误 1. 带有表达式 "ON" 的表达式计算器 "registry" 返回空值,但需要一个值。 (org.mule.api.expression.ExpressionRuntimeException) org.mule.expression.RegistryExpressionEvaluator:101 (http://www.mulesoft.org/docs/site/current3/apidocs/org/mule/api/expression/ExpressionRuntimeException.html) 2.调用store失败。消息负载的类型为:byte[] (org.mule.api.MessagingException)

主要问题是您将 MEL 嵌入到无法工作的 MEL 中。布尔值作为字符串的比较也很狡猾。

替换为:

#[app.registry.storeDownload.contains('#[flowVars.startKey]').equals('false')]

这样:

#[!(app.registry.storeDownload.contains(flowVars.startKey))]

我的用例与 Nazar 的用例有些不同,我需要监控一个很长的 运行 过程,该过程最多可能需要四个小时。

在第一个流程中,我生成一个带有时间戳的键值作为有效负载,然后使用它将 ProcessState 设置为 ObjectStore 中的静态值 'Started',如下所示。之后我延迟四小时触发 Quartz 出站端点。

<objectstore:store config-ref="MonitoredProcess" value-ref="Started" key="#[payload]" doc:name="ObjectStore"/>
<quartz:outbound-endpoint jobName="ProcessMonitor"  responseTimeout="10000" doc:name="Quartz"
    repeatInterval="0" repeatCount="0" startDelay="${process.monitor.event.start.delay}">
    <quartz:scheduled-dispatch-job>
        <quartz:job-endpoint address="vm://processMonitorQueue"/>
    </quartz:scheduled-dispatch-job>
</quartz:outbound-endpoint>

我也遇到了同样的异常。

经过摸索和大量搜索,变量的名称 'value-ref' 结合上面 David 的回答终于揭示了我的问题,即 MEL 总是为此调用 ref 字段.

一旦我将字段更改为 MEL 可以评估的表达式#['Started'],我的问题就消失了。

<objectstore:store config-ref="MonitoredProcess" value-ref="#['Started']" key="#[payload]" doc:name="ObjectStore"/>

为了完整起见,我包含了从 ObjectStore 中检索 ProcessState 的代码。注意defaultValue-ref也需要使用MEL

<vm:inbound-endpoint exchange-pattern="one-way" path="processMonitorQueue" doc:name="VM" />
<objectstore:retrieve config-ref="MonitoredProcess" defaultValue-ref="#['DoesNotExist']" key="#[payload]" targetProperty="processState" doc:name="ObjectStore"/>