【问题标题】:auto-starting Mule flow自动启动骡流
【发布时间】:2015-02-01 08:00:48
【问题描述】:

我正在尝试这种方法来自动启动 Mule 流

Starting a mule flow programmatically using groovy

它不会启动流程。这是使用 3.4.0 CE 在 Mule Studio 中运行的一个非常简单的测试

<?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>

我也试过了,没有运气

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

我假设 flow1 已自动注册但不确定。

【问题讨论】:

    标签: groovy mule


    【解决方案1】:

    通过这种方式,您可以使用 groovy 组件以编程方式启动/停止流程

    <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>
    

    【讨论】:

      【解决方案2】:

      您不应手动启动流程。一旦您在本地或云中或本地部署了您的 mule 应用程序,流程将自动启动。 如果您想停止流程或冻结流程一段时间,那么您可以使用一些 groovy 脚本,例如 sleep(1000);一段时间

      【讨论】:

        【解决方案3】:

        流程会自动启动,您无需“运行”它们。

        消息将根据您在流程中的消息源进行处理,这些消息源触发流程执行。

        我建议您仔细阅读文档: http://www.mulesoft.org/documentation/display/current/Mule+Application+Architecture

        【讨论】:

          【解决方案4】:

          我认为您要做的不是开始流程,而是向它发送一个事件,因此,在您的情况下,您会看到logger 写出hello .

          为此,请使用:

          app.registry.flow1.process(event);
          

          “事件”是DefaultMuleEvent (javadoc) 的一个实例。

          【讨论】:

          • 在我的示例中,我希望 auto2Flow1 在 Mule 服务器启动时启动。它应该调用作为主要流程的 flow1。我尝试用您的声明替换我的 muleContext.registry.lookupFlowConstruct 但显然我遗漏了一些东西,因为它不起作用。
          • 哦,这和你的问题完全不同。你想让 auto2Flow1 在 Mule 启动时被事件触发吗?我不认为有什么可做的。只需在 MuleContextAware Spring bean 上使用 init-method 就可以了。
          猜你喜欢
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2012-03-22
          相关资源
          最近更新 更多