简体   繁体   English

Mule 3.7 / 3.8中的Java组件与全局函数

[英]Java component vs global functions in Mule 3.7/3.8

For some of our flows, we'll have some output attributes (a checksum for instance) that we can't generate directly through DataWeave so we chose to calculate them using Java functions and we have too possibilities : 对于我们的某些流程,我们将具有一些无法直接通过DataWeave生成的输出属性(例如,校验和),因此我们选择使用Java函数来计算它们,并且我们也有很多可能:

  • Use a Java component and put the result on a variable using a transformer class 使用Java组件,然后使用转换器类将结果放在变量上
  • Define a global function that calls a static method from a class and use it in a Transform Message component 定义一个全局函数,该全局函数从类中调用静态方法并在“转换消息”组件中使用

I know that we can have some performance problems with static method as they can't be garbage collected. 我知道静态方法会带来一些性能问题,因为它们无法被垃圾收集。 What are the pros and cons of these 2 choices ? 这两个选择的优缺点是什么?

I think it depends on the complexity of the function. 我认为这取决于功能的复杂性。 Anything you can do in Java you can do directly using MVEL in a global function - no need to call out to a Java static method. 您可以使用Java进行的任何操作,都可以在全局函数中直接使用MVEL进行-无需调用Java静态方法。

The main benefit of using a global function is that you can use MEL/MVEL that may make the function a lot less verbose because of handy MVEL features like property navigation, folds/projections etc. and allows you to access Mule vars/props/payload easily using MEL like #[flowVars.]. 使用全局函数的主要好处是,您可以使用MEL / MVEL,由于方便的MVEL功能(如属性导航,折叠/投影等),您可以使函数的冗长程度降低很多,并允许您访问Mule vars / props / payload像#[flowVars。]一样轻松使用MEL。

But I think if it's a very complicated function then a Java component may be easier for readability/maintenance etc. Also a Java component may be easier to modularise and share with other projects separately. 但是我认为,如果它是一个非常复杂的功能,那么Java组件可能会更易于阅读/维护等。另外,Java组件也可能更易于模块化和分别与其他项目共享。

There may be performance benefits with one over the other, but potentially negligible or you could profile it to see the performance comparison. 彼此之间可能会有性能上的好处,但可能微不足道,或者您可以对其进行概要分析以查看性能比较。

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

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