Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to set sleep into the flow in Mulesoft without losing the message payload

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

like image 708
Stefano Avatar asked Jun 29 '15 12:06

Stefano


3 Answers

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>
like image 174
Anirban Sen Chowdhary Avatar answered Nov 09 '22 15:11

Anirban Sen Chowdhary


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.

like image 3
Víctor Romero Avatar answered Nov 09 '22 15:11

Víctor Romero


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

like image 2
Jorge Garcia Avatar answered Nov 09 '22 14:11

Jorge Garcia