版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
1、2.6消息过滤器( Message Filters) 9 消息选择路由( Choice Routers) 9 消息转换器( Expression Transformers) 10 连接器( Connectors )10 日志组件( Loggers) 10动态端点( Dynamic Endpoints ) 11 表达式组件( Expression Components )12目录一、MEL语法规则及定义21.1 MEL (Mule Expression Language )语法介绍 21.2 MEL 上下文对象(Context Objects) 21.2.1 Server31.2.2 Mule4
2、1.2.3 App51.2.4 Message51.3 MEL运算符61.3.1 数学运算1.3.2 比较运算1.3.3 逻辑运算1.4 MEL 变量(Variables)81.5 数据提取函数( Data Extraction Functions ) 81.3 字典、列表、数组( Map, List, and Array ) 9二、MEL语法实践、MEL语法规则及定义1.1 MEL (Mule Expression Language)语法介绍Mule表达式格式表现为:#表达式语言类似于脚本语言,它允许你用精简的脚本动态实现取值、赋值、操作消息等。如果你想
3、实现更复杂的逻辑,那么建议采用脚本语言,如果你想快速简单的实现取值复制以及函数调用等操作,采用表达式语言更方便。目前 Mule 支持两种表达式语言:1. Mule3.3 以前的版本,表达式格式表现如:#evaluator:expression2. Mule3.3, Mule Expression Language【MEL】,表达式格式表现如:#expression老版本和新版本的不同是,老版本需要指定Evaluator,而新版本就是 MEL本身。语法介绍:表达式描述#2 + 2该表达式取值等于4.#2 + 2 = 4该表达式为逻辑表达式,取值为 true.#message该表达式引用了 MEL
4、中四个上下文对象中的message 对象,该表达式取值为message 对象的值。四个上下文对象包括:(message, app, mule, and server).对象参数介绍请见下文。具体#message .p ayload该表达式链接了 message 对象的payload 属性。#message .p ayloadname该表达式链接了 message 对象的payload 属性中name 变量中的 值。注意,name是由单引号括起来的,这是由于 mule的配置文件 采用的是双引号,所以这里只能使用单引号。#message. payload4同上一表达式一样,只是这里是通过数字索引来
5、引用该值。#message.header .get()该表达式链接了 message对象的header对象,并调用get方法。1.2 MEL上下文对象(Context Objects )Context objects包括消息对象以及它的环境变量。MEL包括四个上下文对象:Server :包括硬件、操作系统、用户、网络接口等属性。Mule :包括Mule实例的所有属性。App :包括当前Mule应用的所有属性。Message :包括当前Mule消息的所有属性。MEL中默认的上下文对象为 省略了 message对象。message。例如:#message.payload可以写为:#payload,
6、即MEL上下文对象属性地图:servermuleappmessagefileSe paratorclusterldencodingidhosthomenamerootIdipnodeldstandalonecorrelationldlocaleversionworkdircorrelationsequencejavaVersionregistrycorrelationGro up SizejavaVendorrepl yToosNamedataT ypeosArchp ayloadosVersioninbound Prop ertiessyste mProp ertiesinboundAtta
7、chmentstimeZoneoutbound Propertiestmp DiroutboundAttachmentsuserNameexce ptionuserHomeuserDir1.2.1 Server该对象的属性仅提供读取不能改写,包括硬件、操作系统、用户、网络接口等信息:名称描述fileSe parator文件路径分隔符(/ on UNIX and on Windows)名称描述host服务器全名,如 ip服务器IP地址javaVendorJRE供应商名称javaVersionJRE版本localeDefault locale (of type
8、 java.util.Locale) of the JRE (can access server.locale.languageand server.locale.country)osArch操作系统架构osName操作系统名称osVersion操作系统版本syste mProp erties系统属性地图timeZoneJRE默认时区tmp DirJRE临时目录userDir用户工作空间目录userHome用户名用户主目录 User home directoryuserName举例:server.userName 表示当前用户的名称。1.2.2 Mule该对象的属性仅提供读取不能改写,包括Mu
9、le实例属性:名称描述clusterIdCluster ID,集群 IDhomeMule服务器安装目录nodeIdCluster node ID ,集群节点 IDversionMule版本1.2.3 App该对象的属性大部分仅能读取,部分可读可写:NameDescri ptionencoding默认编码 Application default encoding ( 只读)name应用名称(只读)standaloneMule是否单机独立服务器,是则返回True (只读)workdir应用工作目录 Application work directory ( 只读)registry当前 Mule应用的
10、变量注册地图Map rep resenting the Mule registry (可读可写)举例:app .registryfoo代表注册在地图中的名称为 foo的对象,可以取值或赋值。1.2.4 MessageThis object p rovides access to the prop erties of the Mule message listed in the table. The meanings of most of these prop erties are documented elsewhere, not here.NameDescri ptionid(只读)root
11、Id(只读)correlationld关联ID(只读)correlationsequence(只读)correlationGro up Size(只读)(可读可写)(只读)repl yTo dataT ypep ayload消息负载(可读可写)inbound Prop ertiesMap (只读)inboundAttachmentsMap (只读)outbound PropertiesMap (可读可写)NameDescri ptionoutboundAttachmentsMap (可读可写)exce ption(只读)1.3 MEL运算符MEL运算符遵循标准JAVA语法,但是操作数都为值类型
12、而非引用类型。 但同样的表达式在 Java中返回false。举例:A = A返回 true,1.3.1数学运算SymbolDefinitionExa mpl e/Value6 fu +力 n法。.For numbers, the value is the sum of the values of1.3.2Symbolthe op erands. For strings, the value is the string formed byconcatenating the values of the op erands.减法。 The value is the value of the firs
13、t op erand minus thevalue of the second.除法。 The value is the value of the first op erand divided bythe value of the second.乘法。The value is the product of the values of theop erands.取余。 The value is the remainder after dividing the value ofthe first op erand by the value of the second.比较运算DefinitionE
14、xa mpl e/Valuebarfubar等于.True if and only if (iff) theA = AtrueThe Stri ng-20.5values of the op erands are equal.!=不等于.True iff the values of theA != BtrueSymbolDefinitionExa mpl e/Valuetrueop erands are unequal.大于。True iff the value on the left isfalsegreater than the value on the right.小于。 True if
15、f the value on the left isless than the value on the right=大于等于。True iff the value on the left5 = 7falseis greater than or equal to the valueon the right.=小于等于。True iff the value on the left5 = 5trueis less than or equal to the value onthe right.contains包含。True iff the string on the right isfubar co
16、ntains bartruea substring of the string on the left.is, instance类型判定。True if the object on the leftfubar is Strin gtrueofis an instance of the class on the right.strsim相似度,取值介于0到1之间,表示两个字符串之间的相似程度。soundslike是否谐音。如果两个字符串发音相似那foo strsimfoofooRobert1.0 foobar strsim0.5soundslike Ruperttrue么返回True。(判断标准
17、依据一种语音算法)1.3.3逻辑运算SymbolDefinitionExa mpl e/Valueand逻辑与.True if both op erands are true.( 注意不(a = b) and (c != d) true iff要使用&,因为可能与配置文件符号冲突 )a =b and c 工 d逻辑或,至少有一个为真则返回 True。true |a nythingSymbolDefinitionExa mpl e/ValueAlways trueorChained OR。从左到右遍历返回第一个不为空的对象。false or or or dogThe String dog1.4
18、MEL 变量(Variables )除了 MEL本地变量(作用区域仅限于当前消息执行器)外,会话变量sessionVars 。MEL还提供两种变量:流程变量flowVars、变量名说明flowVars作用区域为当前flow。你可以在前一个消息执行器设置它的值,在下一个读取。Sessi on Vars作用区域为当前会话。基本与flowVars 一样外,它还可以在flow之间通过Mule End point 进行传递。示例:flowVarsfoo或bar,解释器首先在可以在配置文件中加入以下配置:=sessionVarsbar,如果没有重名的本地变量,甚至可以直接使用 fooflowVars寻找该
19、变量,然后是 sessionVars。如果你不希望解释器自动寻找变量,;i;v/ccnfiguratlcn1.5 数据提取函数(Data Extraction Functions名称说明Xp ath数据提取对象默认为payload ,女0 xpath(7orders/order0);可以显示指定提取对象,女n xpath(7orders/order0, message.inboundAttachmentorde门)Regex返回匹配字符串。如同Xpath,默认也是针对 Payload,也可以显示指定提取对象。如:regex(TBD, message.inboundAttachmentorde门
20、)1.3 字典、列表、数组(MaP, List, and Array )map : key1 : valuel, key2 : value2,. list: item1, item2,.array : item1, item2, . . .,在JAVA中需要指定数组中元素的类型,但在MEL中是无类型的。、MEL语法实践2.1 消息过滤器(Message Filters )Exp ressi on Filter最简单的应用就是判断是否传递该消息还是忽略该消息。Exp re諭M例:.:intound-endcoint ro5.t= +tpertier pcrt=21/IterxpathC) = *
21、bMchttp ott94unc cpdaoint hcct - * rc(n&tc Server * port-SOSO patn-bo&:;inbound-indpsinthomi/ns/dobnlcadf* / vchoiQ;I:jjtboiijrid-s nd point pi th = a ho ne / tuF M irtt: Jouble-cJifkt* select ;cda L:-: outbourd- endpci nt pith=/hcrrsfwe(niic/、:I /-fLch2.3 消息转换器( Expression Transformers消息转换器即根据表达式计算
22、得结果赋予当前消息的Payload 属性。Expression例:irhnijncl-?rriRciriichfln;p-pstt?rn=raLjstrecfKi!thdtler:updstf:stst &= tt me s sa Be H i n tWLrd P ro p ert ie & r st a cs 11: /、2.5日志组件(Loggers)MEL表达式可以为Component提供消息参数等。LoggerLKpres&iom例:*LcGerric55cicFilc Received si:c 亠 *Frrc3 50 6c, in(njndPi-cp=rtic5 FilcSiic
23、kbliewei=THFO-/lUPTtkiQRnf巧pom H卸g右站押r M jcicmiah tMdex ttnt “ yPttjrv申财teltrngiJ WtLjnt#K2.6 动态端点(Dynamic Endpoints)动态端点的含义是 URI中含有MEL表达式的端点。EndlKNM RopertiesFHc (CuTbound Endpofni)The IFire Erdpomc aitawt Mule lophutlona to read orwnte rif& ofliThe locil nie ivrn.Advanwi) aeferencei DocumentationD
24、isplayPath Intormatiior/home/me;Path.#fi.lerame-mesig t. i nboundEpert 4$ 商 3常1 .filena nK.iubstringCfi le NlmtJdstlntkx Off,怙 1:fi Ithamt lensthO)!IChtpyr Pne rn:Cancel例:;vfloh nfl(n5-downLcfldS3rterF13iif*; -ile iinboumid- erdpoint; parri= vnore/iiie/acinicads:/、I; ile:cjtboundenipcint;p日二竹=i*/h3f
25、re/ne/H;fllcncfnr-inciiaet inboundPr oputira f二IcTumr;仁Wnww/urtinM(FiiWJdFtIrictKOfC . )*ljfilehiT-4 -lengrOj|注意:赋值,此例中,#标识符中包含了一组表达式,通过“分号”间隔,第一个表达式给file name第二个表达式是一个JAVA方法调用。2.6表达式组件(Expression Components)表达式组件通过 MEL表达式实现赋值,设置变量等操作。Emip確 Eon例:luprtiMonCgtlhPT IMPQCft估 M ItKfKl IiHKT All tTIlKddM Hnt h A MJiv 尬 uCtTh1*|叱1回 ErrtRlMMW秫WT -两34”TrtEF-riil:ri-E 吟* P冲它K其他高级应用3.1注册Mule应用级对象注册方法:nuleOoTtelflee istrvO reel sth 曲山 hy=ocC) j;获取或者更新方法
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 通讯设备零部件生产线项目建议书
- 2025-2030智慧城市建设技术投资策略决策
- 缓控释肥生产线项目投资计划书
- 2025-2030智慧城市建设咨询服务市场全面分析及城市规划与数字化管理报告
- 2025-2030智慧城市产业行业风险投资发展分析及投资融资策略研究报告
- 2025-2030智慧城市交通行业市场发展趋势与投资潜力研究报告
- 2025-2030智慧城市交通管理系统供需平衡发展前景投资风险评估规划分析报告
- 2025-2030智慧园区建设项目市场调研与增长潜力分析及投资组合研究报告
- 2025-2030智慧医疗互联网行业市场规模调查研究及产业发展现状与市场趋势报告
- 2025-2030智慧农业行业市场深度调研及发展趋势和投资前景预测研究报告
- 2025年广东省深圳市检察机关招录劳动合同制司法辅助人员综合素质测试练习题及答案
- 2024年成人高等考试《医学综合》(专升本)试题真题及答案
- 商会财务工作报告
- 国家开放大学《Python语言基础》实验9:函数定义和调用参考答案
- 干部履历表(中共中央组织部2015年制)
- 学大教育一对一辅导协议
- 产房医院感染控制风险评估表
- 运用PDCA循环降低低分子肝素钠注射后皮下出血发生率
- 地产销售40:思维、标准与技术要点
- 七年级经纬线练习题
- 三菱汽车销售团队建设培训课件
评论
0/150
提交评论