I'd like insert script to delay processing flow in Mulesoft. I have tried to insert script in groovy but I lost the messagge payload, so when I have to get message payload recived null pointer. How can I to do not lose the message payload?
Thanks
If you are using Groovy component in you flow,then you can define sleep() as follow :-
<scripting:component doc:name="Groovy">
<scripting:script engine="Groovy"><![CDATA[
sleep(10000);
return message.payload;]]>
</scripting:script>
</scripting:component>
And remember to return message.payload in Groovy so that you can get the payload at the end or else you will get null payload
Groovy has an issue of loosing payload if you don't return at the end, so, in Groovy you need to return the payload at end, and that's the reason you are receiving null payload
Alternately you can use expression-component as follow:-
<expression-component>
Thread.sleep(10000);
</expression-component>
You can call Thread.sleep from a Java component, a MEL component or even a Groovy component.
However, this is tipically a design flaw unless you are testing something. If this is for production (and a delay is realy-realy-realy needed) consider other solutions like delayed messages using JMS.
In Mule 4 you should use the Runtime "wait" function. Any other alternative will block all your threads. https://docs.mulesoft.com/mule-runtime/4.1/dw-runtime-functions-wait
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With