简体   繁体   English

Mule 4 Groovy 脚本

[英]Mule 4 Groovy Script

Is there any way to call mule "flow" instance using groovy?有什么方法可以使用 groovy 调用 mule“流”实例吗? like When I use the groovy script and it will call the another flow, that means ( calls the another flow -- > sets the variable value and get back with the results).就像当我使用 groovy 脚本时它会调用另一个流程,这意味着(调用另一个流程 --> 设置变量值并返回结果)。 = Expected Behaviour. = 预期行为。

Requirement:要求:

Like, Mule Flow A is running independently and keep on incrementing variable value.比如,Mule Flow A独立运行并不断增加变量值。

Mule flow B wants to access the Flow A variable (Incremental value) ( only variable ) using groovy or python Script. Mule 流B想要使用 groovy 或 python 脚本访问流A变量(增量值)(仅变量)。

Note: Script should not execute flow A for getting variable value.注意:脚本不应执行流A来获取变量值。

Is there method like to get instance of variable in groovy?有没有像在 groovy 中获取变量实例的方法? like

flow=registry.lookupByName('A-flow').getInstance(VariableName)? flow=registry.lookupByName('A-flow').getInstance(VariableName)?

// Need to get only variable value. // 只需要获取变量值。

Groovy Script to call a Mule flow:调用 Mule 流的 Groovy 脚本:

 import org.mule.runtime.api.message.Message;
 import org.mule.runtime.core.api.event.CoreEvent;
 import org.mule.runtime.core.api.event.EventContextFactory;
 flow=registry.lookupByName('A-flow').grep();
 msg = Message.builder().value(payload).build();
 event =CoreEvent.builder(EventContextFactory.create(flow, org.mule.runtime.dsl.api.component.config.
    DefaultComponentLocation.fromSingleComponent("add-location"))).message(msg).build();
 result =flow.process(event);

Mule flow B wants to access the Flow A variable with out deploying or starting the flow A (as it is running independently ) using groovy or python Script. Mule 流 B 想要访问流 A 变量,而无需使用 groovy 或 python 脚本部署或启动流 A(因为它独立运行)。

Variables live inside a Mule Event , which is really what contains the status of an execution triggered from a flow.变量存在于Mule Event中,它实际上包含从流触发的执行状态。 However even if you get a list of all active events you may not know which one is the one you are interested.然而,即使您获得了所有活动事件的列表,您也可能不知道哪一个是您感兴趣的。 It is also a bad practice trying to use Mule internals inside an application.尝试在应用程序中使用 Mule 内部构件也是一种不好的做法。

Instead you should share the value of the variable you are interested using a standard method for Mule, like an object store, a queue or database.相反,您应该使用 Mule 的标准方法共享您感兴趣的变量的值,例如对象存储、队列或数据库。 It really depends on what you are trying to do and the design of your application what is the method that will fit best.这实际上取决于您要尝试做什么以及您的应用程序的设计什么是最适合的方法。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM