【问题标题】:Mule ESB: Outbound property is a date, but inbound property is nullMule ESB:出站属性是日期,但入站属性为空
【发布时间】:2014-01-07 02:04:04
【问题描述】:

我正在使用 Objectstore 模块来跟踪文档的修订号和时间戳。下面的子流程将出站属性“thisTimestamp”设置为新的 Date()。

<sub-flow name="set_revision_and_timestamp" doc:name="set_revision_and_timestamp">
    <enricher doc:name="Message Enricher" target="#[flowVars['OSrecordExists']]" >
        <objectstore:contains config-ref="My_Objectstore" key="#[message.outboundProperties['dbDatabase'] + message.outboundProperties['dbCollection']]" doc:name="Contains"/>
    </enricher>     
    <choice doc:name="Choice" >
        <when expression="#[flowVars['OSrecordExists'] == false]">
        <!-- create a new record with rev num 1 -->
            <objectstore:store config-ref="My_Objectstore" key="#[message.outboundProperties['dbDatabase'] + message.outboundProperties['dbCollection']]" value-ref="#[['revision' : 1, 'timestamp' : new Date()]]" doc:name="Store"/>
        <enricher doc:name="Message Enricher">
            <objectstore:retrieve config-ref="My_Objectstore" key="#[message.outboundProperties['dbDatabase'] + message.outboundProperties['dbCollection']]" doc:name="Retrieve"/>
            <enrich target="#[message.outboundProperties['thisRevision']]" source="#[payload.revision]" />
            <enrich target="#[message.outboundProperties['thisTimestamp']]" source="#[payload.timestamp]" />
        </enricher>
        </when>
        <otherwise>
        <!-- retrieve the record, increment the rev num by 1 and update timestamp, and update the record -->
            <enricher doc:name="Message Enricher">
                <objectstore:retrieve config-ref="My_Objectstore" key="#[message.outboundProperties['dbDatabase'] + message.outboundProperties['dbCollection']]" doc:name="Retrieve"/>
                <enrich target="#[message.outboundProperties['thisRevision']]" source="#[payload.revision]" />
                <enrich target="#[message.outboundProperties['thisTimestamp']]" source="#[payload.timestamp]" />
            </enricher>
            <set-property propertyName="thisRevision" value="#[message.outboundProperties['thisRevision'] + 1]" doc:name="Increment Rev#"/>
            <set-property propertyName="thisTimestamp" value="#[new Date()]" doc:name="New timestamp"/>
            <objectstore:store config-ref="My_Objectstore" key="#[message.outboundProperties['dbDatabase'] + message.outboundProperties['dbCollection']]" overwrite="true" value-ref="#[['revision' : message.outboundProperties['thisRevision'], 'timestamp' : message.outboundProperties['thisTimestamp']]]" doc:name="Store"/>
        </otherwise>
    </choice>
</sub-flow>

然后使用 ActiveMQ 将消息发送到 JMS 出站端点,并由另一个 ActiveMQ JMS 入站端点接收。记录器显示该属性已在出站范围thisTimestamp=Thu Jan 02 15:04:08 EST 2014 上设置,但相应的入站范围属性为空。什么给了?

编辑添加:有趣的是,当我检查 AMQ 队列上的消息时,thisTimestamp 属性也没有设置。

【问题讨论】:

    标签: mule


    【解决方案1】:

    如果您正在通过 &lt;when&gt; 路径,那么这是预期的行为,因为属性不会传播到丰富器范围之外: http://www.mulesoft.org/docs/site/current/apidocs/org/mule/enricher/MessageEnricher.html

    实现丰富资源的消息处理器是 使用当前消息的副本以及任何流或 存在的会话变量。调用此消息 处理器在主流程的单独上下文中完成,因此任何 修改消息(及其属性和附件)或 流或会话变量不会反映在流中 浓缩器已配置。

    【讨论】:

    • &lt;when&gt;&lt;otherwise&gt; 都包含相同的浓缩器,它们都针对两个出站属性,thisRevisionthisTimestamp。 “丰富(或修改)消息的方式是通过显式配置丰富资源的结果与使用 Mule 表达式的消息之间的映射(源 -> 目标)。Mule 表达式用于选择要成为的值从丰富资源(源)返回的结果中提取,并定义将这个值插入到消息(目标)中的位置。”
    【解决方案2】:

    复制我在 Mule 社区论坛上收到的来自用户 John Stegeman 的正确答案:

    刚刚看了下源码:https://github.com/mulesoft/mule/blob/mule-3.x/transports/jms/src/main/java/org/mule/transport/jms/transformers/AbstractJmsTransformer.java

    看来应该可以了。我采用了我的一个使用 ActiveMQ 队列的流程,并尝试了它。日期不显示。如果我 toString() 它的日期。

    查看 JMS 规范可以解开这个谜团:

    http://docs.oracle.com/javaee/1.4/api/javax/jms/Message.html 告诉我们:

    属性值可以是 boolean、byte、short、int、long、float、double 和 String。

    这就是原因。您不能使用日期。

    【讨论】:

      猜你喜欢
      • 2016-11-08
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-07-13
      • 2018-08-02
      • 1970-01-01
      • 2013-12-06
      相关资源
      最近更新 更多