Setting and Reading properties on MuleMessage

View: New views
3 Messages — Rating Filter:   Alert me  

Setting and Reading properties on MuleMessage

by Marco Mascia-2 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hi all,
I'm stuck in a problem with message properties.
The task I'm trying to accomplish is straightforward:

I would set a property in a mule message using a message-properties-transformer in the inbound router and read the value in the outbound endpoint using expression framework
Im more depth, here's my configuration:

           <service name="local.eventi.update.write">
            <inbound>
                <vm:inbound-endpoint path="local.eventi.update.write" connector-ref="directVm" >              
                     <message-properties-transformer>
                               <add-message-properties key="tstamp" value="2009-10-01"/>                      
                    </message-properties-transformer>                              
                </vm:inbound-endpoint>            
            </inbound>
            <outbound>
                <chaining-router>
                    <jdbc:outbound-endpoint connector-ref="DB_VLOCAL_AZIENDE"
                        synchronous="true" queryKey="batchReplaceEventi" />                                        
                    <vm:outbound-endpoint path="recs.console.insert" transformer-refs="local.eventi.update.write.ok" connector-ref="directVm">                        
                    </vm:outbound-endpoint>
                </chaining-router>
            </outbound>            
        </service>

But the message received by the component doesn't contains the property "tstamp".
So I changed my inbound configuration to this:

                 <vm:inbound-endpoint path="local.eventi.update.write" connector-ref="directVm" >
                       <property key="tstamp" value="2009-10-01"/>                                                                        
                </vm:inbound-endpoint>
and that seems to work (the tstamp property is added to the message)

In my outbound router,I tried to access the variable using the following expressions:

#[mule:message.headers(tstamp)]
#[mule:message.header(tstamp)]#[headers:tstamp]
#[header:tstamp]

but the result is always null.

So, my questions are:

1- what am I doing wrong with the message-properties-transformer
? Wasn't it supposed to do exactly what I wanted to do?
2- how can I read via expression evaluation the tstamp property?

Thank to all in advance,
stefano

---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email



Parent Message unknown Re: Setting and Reading properties on MuleMessage

by Andrew Perepelytsya :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

I wonder if this is some special behavior of the vm transport, as it works for jms last time i checked. Can you try replacing inbound with e.g. http endpoint?

HTH,
Andrew

On Oct 1, 2009 9:06 AM, "stefano dellafiore" <mule.dev.relay@...> wrote:

Hi all,
I'm stuck in a problem with message properties.
The task I'm trying to accomplish is straightforward:

I would set a property in a mule message using a message-properties-transformer in the inbound router and read the value in the outbound endpoint using expression framework
Im more depth, here's my configuration:

          &lt;service name="local.eventi.update.write"&gt;
           &lt;inbound&gt;
               &lt;vm:inbound-endpoint path="local.eventi.update.write" connector-ref="directVm" &gt;
                    &lt;message-properties-transformer&gt;
                              &lt;add-message-properties key="tstamp" value="2009-10-01"/&gt;
                   &lt;/message-properties-transformer&gt;
               &lt;/vm:inbound-endpoint&gt;
           &lt;/inbound&gt;
           &lt;outbound&gt;
               &lt;chaining-router&gt;
                   &lt;jdbc:outbound-endpoint connector-ref="DB_VLOCAL_AZIENDE"
                       synchronous="true" queryKey="batchReplaceEventi" /&gt;
                   &lt;vm:outbound-endpoint path="recs.console.insert" transformer-refs="local.eventi.update.write.ok" connector-ref="directVm"&gt;
                   &lt;/vm:outbound-endpoint&gt;
               &lt;/chaining-router&gt;
           &lt;/outbound&gt;
       &lt;/service&gt;

But the message received by the component doesn't contains the property "tstamp".
So I changed my inbound configuration to this:

                &lt;vm:inbound-endpoint path="local.eventi.update.write" connector-ref="directVm" &gt;
                      &lt;property key="tstamp" value="2009-10-01"/&gt;
               &lt;/vm:inbound-endpoint&gt;
and that seems to work (the tstamp property is added to the message)

In my outbound router,I tried to access the variable using the following expressions:

#[mule:message.headers(tstamp)]
#[mule:message.header(tstamp)]#[headers:tstamp]
#[header:tstamp]

but the result is always null.

So, my questions are:

1- what am I doing wrong with the message-properties-transformer
? Wasn't it supposed to do exactly what I wanted to do?
2- how can I read via expression evaluation the tstamp property?

Thank to all in advance,
stefano

---------------------------------------------------------------------
To unsubscribe from this list, please visit:

   http://xircles.codehaus.org/manage_email



Re: Setting and Reading properties on MuleMessage

by Marco Mascia-2 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Ok, I fixed the problem by myself. There was a problem with some custom code accessing the property value.

But I still have a question about setting the property. The only way I found to set a dynamic value in my message header was via <script:transformer>:

<vm:inbound-endpoint path="local.eventi.update.write" connector-ref="directVm" >
       
<script:transformer>
            <script:script engine="groovy">
               
import java.text.DateFormat;
                import java.text.SimpleDateFormat;

                DateFormat f = new SimpleDateFormat("yyyy-MM-dd HH:mm");
                message.setProperty("tstamp",f.format(new GregorianCalendar().getTime()));
                return message;
            </script:script>
         </script:transformer>


</vm:inbound-endpoint>


because <property> tag doesn't seem to evaluate dynamic expression  and  <message-property-transformer>  doesn't seem to set the property at all .I think I'm missing something using of message-property-transformer. What is it supposed to do?


I don't like very much groovy scripts in my configuration file, so I would ask if someone knows a better way to do that.


s.


 


 



---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email