0
votes

I'm using the Objectstore module to track a document's revision number and timestamp. The subflow below sets the outbound property "thisTimestamp" as a new 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>

The message is then sent to a JMS outbound-endpoint using ActiveMQ, and received by another ActiveMQ JMS inbound-endpoint. Loggers show that the property has been set on the outbound scope, thisTimestamp=Thu Jan 02 15:04:08 EST 2014, but the corresponding inbound scoped property is null. What gives?

Edited to add: Interestingly, when I examine the message on an AMQ queue, the thisTimestamp property is not set either.

2

2 Answers

0
votes

If you are going through the <when> path then it's the expected behavior, since properties are not propagated outside of the enricher scope: http://www.mulesoft.org/docs/site/current/apidocs/org/mule/enricher/MessageEnricher.html

The Message Processor that implements the Enrichment Resource is invoked with a copy of the current message along with any flow or session variables that are present. Invocation of the this message processor is done in a separate context to the main flow such that any modification to the message (and it's properties and attachments) or flow or session variables will not be reflected in the flow where the enricher is configured.

0
votes

Copying the correct answer I received on the Mule community forum, from user John Stegeman:

Just had a look at the source code: https://github.com/mulesoft/mule/blob/mule-3.x/transports/jms/src/main/java/org/mule/transport/jms/transformers/AbstractJmsTransformer.java

It appears that it should work. I took one of my flows that used ActiveMQ queues, and tried it. The date doesn't show up. If I toString() the Date it does.

Having a look at the JMS spec solves this mystery:

http://docs.oracle.com/javaee/1.4/api/javax/jms/Message.html tells us:

Property values can be boolean, byte, short, int, long, float, double, and String.

That would be the reason. You cannot use a Date.