Mule表达式语言和全局函数用于筛选记录

Mule表达式语言和全局函数用于筛选记录,mule,dataweave,Mule,Dataweave,我有一个通用函数,可供多个dataweave转换使用,因此我想将其作为MEL全局函数编写 我配置了全局函数文件- <configuration doc:name="Configuration"> <expression-language> <import class="org.apache.commons.lang3.StringUtils"></import> <global-

我有一个通用函数,可供多个dataweave转换使用,因此我想将其作为MEL全局函数编写

我配置了全局函数文件-

<configuration doc:name="Configuration">
        <expression-language>
            <import class="org.apache.commons.lang3.StringUtils"></import>
            <global-functions file="global_expressions.mvel">
            </global-functions>
        </expression-language>
    </configuration>

然后我有一个global_expressions.mvel文件,其中我需要一个函数,如-

def filterE1Records(route,type){
                    if(type == 'COR'){
                        return (route >= '${min.route}' and route <= '${max.route}');
                    } else if(type == 'NONCOR'){
                        return ((route >= '${min.route}' and route <= '${max.route}') == false and route != '${ndsin.route}');
                    } else if(type == 'NDS'){
                        return route == '${ndsin.route}';
                    } else {
                        return false;
                    }

                }
def过滤器1记录(路线、类型){
如果(类型=='COR'){
return(route>='${min.route}'和route='${min.route}'和route=10000和route=10000和route
根据comments中的讨论,我将假设属性解析在导入的MEL文件中不起作用

您可以通过Spring setter注入在bean中加载这些不同的属性,或者使用Spring的实用程序在
java.util.properties
对象中加载这些不同的属性,然后使用以下工具查找它们:

app.registry.myConfigBean.minRoute
或:


从您的问题来看,不清楚您的问题是由于占位符未得到解决,还是因为事实测试仅适用于基于字符串的比较。您说使用
code>=10000
有效,但当您删除
'
时则无效,这听起来很矛盾。您确定占位符在
全局表达式中得到解决吗s、 mvel
?感谢@DavidDossot了解占位符是否正在解析
global\u expressions.mvel
文件中的属性?我确定并验证了我是否像p('min.route')一样直接将占位符放入dataweave中然后它正确解析,这意味着属性配置正确。我认为我无法在表达式文件中调试。我的意思是
route>=10000
可以工作,但是
route>='${min.route}'
对相同的输入记录不起作用。我不明白为什么要引用占位符?假设它可以解析,您想使用
route>=${min.route}
否则,您将执行字符串比较,而不是数字比较。此外,无论您在Java中可以做什么,您都应该能够在MEL中执行,因此您应该能够使用
System.out
甚至创建一个SLF4J记录器并使用它,只是为了调试并查看是否在
${min.route}中获得一个值
谢谢,我尝试了并得到了属性未解决错误,不确定我之前是如何忽略它的:)抱歉,我错了,似乎属性没有加载到
全局表达式中。mvel
,即使它们可以在dataweave和mule的其余部分中正确访问。现在我将函数定义更改为
def filterE1Records(route,type,cmin,cmax,ndsin)
并从dataweave调用函数,如
有效负载过滤器(filter1records($.route as:number,flowVars.RecordType,p('min.route')、p('max.route')、p('ndsin.route'))
app.registry.myConfigBean.minRoute
app.registry.myConfigProperties['min.route']