MEL语法学习笔记v2.docx_第1页
MEL语法学习笔记v2.docx_第2页
MEL语法学习笔记v2.docx_第3页
MEL语法学习笔记v2.docx_第4页
MEL语法学习笔记v2.docx_第5页
免费预览已结束,剩余9页可下载查看

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

目录一、MEL语法规则及定义21.1 MEL(Mule Expression Language)语法介绍21.2 MEL上下文对象(Context Objects)21.2.1 Server31.2.2 Mule41.2.3 App51.2.4 Message51.3 MEL运算符61.3.1 数学运算61.3.2 比较运算61.3.3 逻辑运算71.4 MEL变量(Variables)81.5 数据提取函数(Data Extraction Functions)81.3 字典、列表、数组(Map, List, and Array)9二、MEL语法实践92.1 消息过滤器(Message Filters)92.2 消息选择路由(Choice Routers)92.3 消息转换器(Expression Transformers)102.4 连接器(Connectors)102.5 日志组件(Loggers)102.6 动态端点(Dynamic Endpoints)112.6 表达式组件(Expression Components)12一、MEL语法规则及定义1.1 MEL(Mule Expression Language)语法介绍Mule表达式格式表现为:# .表达式语言类似于脚本语言,它允许你用精简的脚本动态实现取值、赋值、操作消息等。如果你想实现更复杂的逻辑,那么建议采用脚本语言,如果你想快速简单的实现取值复制以及函数调用等操作,采用表达式语言更方便。目前Mule支持两种表达式语言:1. Mule3.3以前的版本,表达式格式表现如:#evaluator:expression2. Mule3.3,Mule Expression Language【MEL】,表达式格式表现如:#expression老版本和新版本的不同是,老版本需要指定Evaluator,而新版本就是MEL本身。语法介绍:表达式描述#2 + 2该表达式取值等于 4.#2 + 2 = 4该表达式为逻辑表达式,取值为 true.#message该表达式引用了MEL中四个上下文对象中的message对象,该表达式取值为message对象的值。四个上下文对象包括: (message,app,mule, andserver). 具体对象参数介绍请见下文。#message.payload该表达式链接了message对象的payload属性。#message.payloadname该表达式链接了message对象的payload属性中name变量中的值。注意,name是由单引号括起来的,这是由于mule的配置文件采用的是双引号,所以这里只能使用单引号。#message.payload4同上一表达式一样,只是这里是通过数字索引来引用该值。#message.header.get()该表达式链接了message对象的header对象,并调用get方法。1.2 MEL上下文对象(Context Objects)Context objects 包括消息对象以及它的环境变量。MEL包括四个上下文对象:Server: 包括硬件、操作系统、用户、网络接口等属性。Mule: 包括Mule实例的所有属性。App: 包括当前Mule应用的所有属性。Message: 包括当前Mule消息的所有属性。MEL中默认的上下文对象为message。例如:#message.payload可以写为:#payload,即省略了message对象。MEL上下文对象属性地图:servermuleappmessagefileSeparatorclusterIdencodingidhosthomenamerootIdipnodeIdstandalonecorrelationIdlocaleversionworkdircorrelationSequencejavaVersionregistrycorrelationGroupSizejavaVendorreplyToosNamedataTypeosArchpayloadosVersioninboundPropertiessystemPropertiesinboundAttachmentstimeZoneoutboundPropertiestmpDiroutboundAttachmentsuserNameexceptionuserHomeuserDir1.2.1 Server该对象的属性仅提供读取不能改写,包括硬件、操作系统、用户、网络接口等信息:名称描述fileSeparator文件路径分隔符( / on UNIX and on Windows)host服务器全名,如ip服务器IP地址javaVendorJRE 供应商名称javaVersionJRE 版本localeDefault locale (of type java.util.Locale) of the JRE (can access server.locale.language and server.locale.country)osArch操作系统架构osName操作系统名称osVersion操作系统版本systemProperties系统属性地图timeZoneJRE默认时区tmpDirJRE临时目录userDir用户工作空间目录userHome用户主目录User home directoryuserName用户名举例: server.userName 表示当前用户的名称。1.2.2 Mule该对象的属性仅提供读取不能改写,包括Mule实例属性:名称描述clusterIdCluster ID,集群IDhomeMule服务器安装目录nodeIdCluster node ID,集群节点IDversionMule 版本1.2.3 App该对象的属性大部分仅能读取,部分可读可写:NameDescriptionencoding默认编码Application default encoding (只读)name应用名称 (只读)standaloneMule是否单机独立服务器,是则返回True (只读)workdir应用工作目录Application work directory (只读)registry当前Mule应用的变量注册地图Map representing the Mule registry (可读可写)举例: app.registryfoo 代表注册在地图中的名称为foo的对象,可以取值或赋值。1.2.4 MessageThis object provides access to the properties of the Mule message listed in the table. The meanings of most of these properties are documented elsewhere, not here.NameDescriptionid(只读)rootId(只读)correlationId关联ID (只读)correlationSequence(只读)correlationGroupSize(只读)replyTo(可读可写)dataType(只读)payload消息负载(可读可写)inboundPropertiesMap (只读)inboundAttachmentsMap (只读)outboundPropertiesMap (可读可写)outboundAttachmentsMap (可读可写)exception(只读)1.3 MEL运算符MEL运算符遵循标准JAVA语法,但是操作数都为值类型而非引用类型。举例: A = A 返回true,,但同样的表达式在Java中返回false。1.3.1 数学运算SymbolDefinitionExample/Value+加法。. For numbers, the value is the sum of the values of the operands. For strings, the value is the string formed by concatenating the values of the operands.2 + 46fu + barThe String fubar-减法。 The value is the value of the first operand minus the value of the second.2 - 4-2/除法。 The value is the value of the first operand divided by the value of the second.2 / 40.5*乘法。The value is the product of the values of the operands.2 * 48%取余。 The value is the remainder after dividing the value of the first operand by the value of the second.9 % 411.3.2 比较运算SymbolDefinitionExample/Value=等于. True if and only if (iff) the values of the operands are equal.A = Atrue!=不等于. True iff the values of the operands are unequal.A != Btrue大于。True iff the value on the left is greater than the value on the right.7 5true小于。 True iff the value on the left is less than the value on the right5 =大于等于。True iff the value on the left is greater than or equal to the value on the right.5 = 7false=小于等于。True iff the value on the left is less than or equal to the value on the right.5 = 5truecontains包含。True iff the string on the right is a substring of the string on the left.fubar contains bartrueis,instance of类型判定。True if the object on the left is an instance of the class on the right.fubar is Stringtruestrsim相似度,取值介于0到1之间,表示两个字符串之间的相似程度。foo strsim foo1.0foobar strsim foo0.5soundslike是否谐音。如果两个字符串发音相似那么返回True。(判断标准依据一种语音算法)Robert soundslike Ruperttrue1.3.3 逻辑运算SymbolDefinitionExample/Valueand逻辑与. True if both operands are true. (注意不要使用&,因为可能与配置文件符号冲突)(a = b) and (c != d)true iff a =b and c d|逻辑或.。至少有一个为真则返回True。true |anythingAlwaystrueorChained OR。从左到右遍历返回第一个不为空的对象。false or or or dogThe String dog1.4 MEL变量(Variables)除了MEL本地变量(作用区域仅限于当前消息执行器)外,MEL还提供两种变量:流程变量flowVars、会话变量sessionVars。变量名说明flowVars作用区域为当前flow。你可以在前一个消息执行器设置它的值,在下一个读取。SessionVars作用区域为当前会话。基本与flowVars一样外,它还可以在flow之间通过Mule Endpoint进行传递。示例:flowVarsfoo = sessionVarsbar,如果没有重名的本地变量,甚至可以直接使用foo或bar,解释器首先在flowVars寻找该变量,然后是sessionVars。如果你不希望解释器自动寻找变量,可以在配置文件中加入以下配置:1.5 数据提取函数(Data Extraction Functions)名称说明Xpath数据提取对象默认为payload,如xpath(/orders/order0);可以显示指定提取对象,如xpath(/orders/order0, message.inboundAttachmentorder)Regex返回匹配字符串。如同Xpath,默认也是针对payload,也可以显示指定提取对象。如:regex(TBD, message.inboundAttachmentorder)1.3 字典、列表、数组(Map, List, and Array)map:key1 : value1, key2 : value2, . . .;list:item1, item2, . . .;array:item1, item2, . . .,在JAVA中需要指定数组中元素的类型,但在MEL中是无类型的。二、MEL语法实践2.1 消息过滤器(Message Filters)Expression Filter最简单的应用就是判断是否传递该消息还是忽略该消息。例:2.2 消息选择路由(Choice Routers)选择路由作用就是根据MEL表达式将消息导向正确的分支。例:2.3 消息转换器(Expression Transformers)消息转换器即根据表达式计算得结果赋予当前消息的payload属性。例:2.4 连接器(Connectors)MEL表达式可以为连接器的参数或属性赋值,传递参数等。例:2.5 日志组件(Lo

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论