mulemule-componentmule4

How to store the current date and message id in Mule 4 variable?


In my case, I'm doing a migration from Mule 3 to Mule 4.

I want to store the current date and message id in mule 4 variables.

Date formate is current date in "yyyyMMddHHmmssSSS"

Message_id is date ++ (random id (size is 6 characters))

code in mule 3:

<set-variable variableName="messageDateF" value="#[server.dateTime.format('yyyyMMddHHmmssSSS')]" doc:name="set messageDateF"/>
<set-variable variableName="messageId" value="#[flowVars.messageDateF]#[UUID.randomUUID().toString().replace('-', '').substring(0,5)]" doc:name="set messageId"/>

Expected output:

20220202024435724ddebd

Please assist me.


Solution

  • This is the equivalent set-variable for Mule 4.3. Note that I only used one variable. You can separate into two variables if really need both.

    <set-variable variableName="messageId" value="#[now() as String {format: "yyyyMMddHHmmssSSS"} ++ (uuid() replace ("-") with "")[0 to 5]]" doc:name="set messageId"/>