Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Message Enricher and variables

Tags:

mule

I"m having a hard time realizing something from the documentation.

What i'd like to do is to to enrich the current payload with a simple int.

Could i do that staticly from the enricher syntax or would i have to create an outbound request-reaponse endpoint just for that silly thing?

For example, i am looking for the somethinga lone the lines of:

 <enricher target="#[variable:age]" source="SomeStringIwant"/>

That obviously would not work, is there some way to get it to work easily?

Thanks

like image 457
Menyh Avatar asked Apr 08 '26 09:04

Menyh


1 Answers

I would use a script transformer for this:

<script:transformer>
    <script:script engine="groovy">
        <script:text>
            payload.age = message.getInboundProperty('ageProperty')
            return payload
        </script:text>
    </script:script>
</script:transformer>

This script assumes the 'ageProperty' is in the inbound scope. If not, use the method for the right scope.

This script also relies on two of the implicit variables bound in the context of a script transformer:

  • payload: an Object carried by the current message, as you can get it with MuleMessage.getPayload.
  • message: the in-flight MuleMessage as carried by the current MuleEvent.
like image 197
David Dossot Avatar answered Apr 24 '26 17:04

David Dossot