Mule ESB:出站属性是日期,但入站属性为空

时间:2014-01-02 20:27:24

标签: mule

我正在使用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上设置,但相应的入站范围属性为null。是什么给了什么?

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

2 个答案:

答案 0 :(得分:0)

如果您正在浏览<when>路径,那么这是预期的行为,因为属性不会在更丰富的范围之外传播: http://www.mulesoft.org/docs/site/current/apidocs/org/mule/enricher/MessageEnricher.html

  

实现增强资源的消息处理器是   调用当前消息的副本以及任何流或   存在的会话变量。调用此消息   处理器是在主流的单独上下文中完成的   修改消息(及其属性和附件)或   流量或会话变量不会反映在流量所在的位置   配置了richher。

答案 1 :(得分:0)

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

刚看了一下源代码: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。

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

相关问题