我保持我的一个流量说'流动A'在"停止"作为初始状态。然后在另一个流程中说流程B'使用groovy脚本或MEL表达;我正在开始同样的流程A'。在流程A'的最后,我以编程方式停止流程。
现在,如果我再次启动流程A'通过'流程B'它没有说''流A'已经开始了;无法重新启动。
任何解决方案。
我想随时开始流动,保持初始状态为停止状态。最后再次使用脚本停止流程。
以下是代码:
<flow name="FlowB">
<poll doc:name="Poll">
<logger level="INFO" doc:name="Logger"/>
</poll>
<logger level="INFO" doc:name="Logger" message="triggered"/>
<scripting:component doc:name="Groovy">
<scripting:script engine="Groovy"><![CDATA[muleContext.registry.lookupFlowConstruct('FlowB').start()]]></scripting:script>
</scripting:component>
<logger level="INFO" doc:name="Logger"/>
<expression-component doc:name="Expression"><![CDATA[app.registry.FlowA.stop();]]></expression-component>
</flow>
<flow name="FlowA" initialState="stopped">
<sqs:receive-messages config-ref="Amazon_SQS__Configuration" doc:name="Amazon SQS (Streaming)"/>
<logger level="INFO" doc:name="Logger"/>
</flow>
我正在使用poller启动流程A.所以,如果我再次运行流程B来启动流程A;它抛出异常。
答案 0 :(得分:0)
停止flowA
无效(无论出于何种原因)或您在停止后立即尝试启动flowA
。 AFAIK启动/停止是异步发生的,这意味着即使已经返回了stop()方法,flowA
也可能处于启动状态。
这是一个展示/stop
和/start
http-endpoints的工作示例。
<mule xmlns:scripting="http://www.mulesoft.org/schema/mule/scripting" xmlns:tracking="http://www.mulesoft.org/schema/mule/ee/tracking" xmlns:http="http://www.mulesoft.org/schema/mule/http" 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"
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/http http://www.mulesoft.org/schema/mule/http/current/mule-http.xsd
http://www.mulesoft.org/schema/mule/ee/tracking http://www.mulesoft.org/schema/mule/ee/tracking/current/mule-tracking-ee.xsd
http://www.mulesoft.org/schema/mule/scripting http://www.mulesoft.org/schema/mule/scripting/current/mule-scripting.xsd">
<http:listener-config name="HTTP_Listener_Configuration" host="0.0.0.0" port="8081" doc:name="HTTP Listener Configuration"/>
<flow name="flowA">
<logger message="foobar" level="INFO" doc:name="Logger"/>
</flow>
<flow name="flowB_start">
<http:listener config-ref="HTTP_Listener_Configuration" path="/start" doc:name="HTTP"/>
<expression-transformer expression="#[groovy:muleContext.registry.get('flowA').start()]" doc:name="Expression"/>
</flow>
<flow name="flowB_stop">
<http:listener config-ref="HTTP_Listener_Configuration" path="/stop" doc:name="HTTP"/>
<expression-transformer expression="#[groovy:muleContext.registry.get('flowA').stop()]" doc:name="Expression"/>
</flow>
</mule>
我可以随时开始/停止flowA
。
答案 1 :(得分:0)
这很容易处理,而且非常简单。您可以使用If else
条件来控制它。如果FlowA已经启动,它将忽略,否则它将从以下开始。
<flow name="flowA" initialState="stopped">
<http:listener config-ref="HTTP_Listener_Configuration" path="/flowA" doc:name="HTTP"/>
<logger message="In flow A" level="INFO" doc:name="Logger"/>
</flow>
<flow name="flowB">
<http:listener config-ref="HTTP_Listener_Configuration" path="/flowB" doc:name="HTTP"/>
<scripting:component>
<scripting:script engine="groovy">
if(muleContext.registry.lookupFlowConstruct('flowA').isStarted())
{
System.out.println("flowA already started ... ignoring and do nothing")
}
else
{
muleContext.registry.lookupFlowConstruct('flowA').start()
}
</scripting:script>
</scripting:component>
</flow>
<强>更新强>
<flow name="FlowB">
<poll doc:name="Poll">
<fixed-frequency-scheduler frequency="3000" />
<logger level="INFO" doc:name="Logger" message="FlowB" />
</poll>
<logger message="test" level="INFO" doc:name="Logger" />
<scripting:component doc:name="Script">
<scripting:script engine="groovy"><![CDATA[
if(muleContext.registry.lookupFlowConstruct('FlowA').isStarted())
{
System.out.println("flowA already started ... ignoring and do nothing")
}
else
{
muleContext.registry.lookupFlowConstruct('FlowA').start()
}]]>
</scripting:script>
</scripting:component>
<flow-ref name="FlowA" doc:name="FlowA" />
<expression-component doc:name="Expression"><![CDATA[app.registry.FlowA.stop();]]></expression-component>
</flow>
<flow name="FlowA" initialState="stopped">
<http:listener config-ref="HTTP_Listener_Configuration" path="/test" doc:name="HTTP" />
<logger level="INFO" doc:name="Logger" message="In flowA" />
</flow>