auto-starting Mule flow

北城以北 提交于 2020-01-17 06:12:28

问题


I'm trying this approach to autostart a Mule flow

Starting a mule flow programmatically using groovy

and it does not start the flow. Here's a very simple test run in Mule Studio with the 3.4.0 CE

<?xml version="1.0" encoding="UTF-8"?>
<mule xmlns:scripting="http://www.mulesoft.org/schema/mule/scripting"     
xmlns="http://www.mulesoft.org/schema/mule/core" xmlns:doc="http://www.mulesoft.org/schema/mule/documentation"
xmlns:spring="http://www.springframework.org/schema/beans" version="CE-3.4.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans     
http://www.springframework.org/schema/beans/spring-beans-current.xsd
http://www.mulesoft.org/schema/mule/core http://www.mulesoft.org/schema/mule/core/current/mule.xsd
http://www.mulesoft.org/schema/mule/scripting http://www.mulesoft.org/schema/mule/scripting/current/mule-scripting.xsd">

<flow name="auto2Flow1" doc:name="auto2Flow1">
    <scripting:component doc:name="Groovy">
        <scripting:script engine="Groovy">
             muleContext.registry.lookupFlowConstruct('flow1').start()
        </scripting:script>
    </scripting:component>
</flow>

<flow name="flow1" doc:name="flow1">
    <logger level="INFO" doc:name="Logger" message="hello"/>
</flow>

</mule>

I also tried this with no luck

<expression-component>
   app.registry.flow1.start();
</expression-component>

I'm assuming flow1 is automatically registered but not sure.


回答1:


I think that what you are trying to do is not starting the flow but instead send an event to it so, in your case, you'll see the logger write out hello.

For this, use:

app.registry.flow1.process(event);

with 'event' being an instance of DefaultMuleEvent (javadoc).




回答2:


Flows are automatically started, you don't need to "run" them.

Messages will be processed depending on the message sources you have in your flows, which are the ones triggering the flow execution.

I would suggest you to carefully read the documentation: http://www.mulesoft.org/documentation/display/current/Mule+Application+Architecture




回答3:


You should not start the flow manually. Once you deployed your mule application locally or in cloud or on premise the flow will start automatically. If you would like to stop the flow or freeze the flow for some time then you can use some groovy Script something like sleep(1000); for some time




回答4:


This way you can start/stop your flow programmatically by using groovy component

<scripting:component doc:name="start/stop the flows">
<scripting:script engine="Groovy">
<![CDATA[muleContext.registry.lookupFlowConstruct('my-Flow-1').start();
muleContext.registry.lookupFlowConstruct('my-Flow-2').start();
muleContext.registry.lookupFlowConstruct('myFlow-3').stop();
]]></scripting:script></scripting:component>


来源:https://stackoverflow.com/questions/27277106/auto-starting-mule-flow

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!