Monday, January 18, 2016

Generate Unique Random Value using Function in Mule

Recently stumbled on a functionality in Mulesoft where I had to assign unique random Id to one of the variables in my code. Generally I would have used a Java component to generate UUID and assign the same to variable in Java itself.

But, Thanks to mule's intelligent MEL one doesnt have to write most of the stuff in Java. Following is the example.


<set-variable variableName="RandomValue" value="#[function:uuid]" doc:name="Variable" />

And ... That is it :) !!!!

I just wrote a small flow below to test it and seems to be pretty elegant solution ....



Executed multiple times from browser: http://http://localhost:8081/ and following is the result ... seems pretty unique !! .. Could be the smallest post on Mulesoft so far... :)