Studio+Update+Sites11Mule Expression Language MELWord文档格式.docx
- 文档编号:19264043
- 上传时间:2023-01-04
- 格式:DOCX
- 页数:66
- 大小:445.21KB
Studio+Update+Sites11Mule Expression Language MELWord文档格式.docx
《Studio+Update+Sites11Mule Expression Language MELWord文档格式.docx》由会员分享,可在线阅读,更多相关《Studio+Update+Sites11Mule Expression Language MELWord文档格式.docx(66页珍藏版)》请在冰豆网上搜索。
ratherthanusingmultipleexpressionevaluators,youcanuseMEL,thedefaultexpressionevaluator,toconsistentlyaccessandmanipulateinformation.
MELexpressionsworkwithinmessageprocessorstomodifythewaytheprocessorsactuponthemessagesuchasroutingorfiltering.TheexamplebelowdemonstrateshowyoucanuseMELtologthevalueofaflowvariableatruntime.
<
loggermessage="
Thevalueinmyfirstvariableis#[flowVars.myVar1]"
level="
INFO"
/>
An
expressionlanguage,suchasMEL,
issimilar,butnotthesameas,a
scriptinglanguage:
itallowsyoutowriteshortscriptsthatresolvedynamicallytogetvalues,setvalues,orperformanoperationondata.Thereisanoverlapinfunctionalitybetweenanexpressionlanguageandascriptinglanguage,butscriptinglanguagesaregenerallymoreusefulifyouarewritingsomethingcomplexenoughtorequiremorethanjustafewlinesofcode,orifyouneedtoincludeconditionallogic.If,however,youneedtogetorsetvalues,invokemethods,orperformfunctions,youcandosoquicklyandeasilyusinganexpressionlanguage.
UsingMEL
BasedoninformationMuleextractsfromthemessageoritsenvironmentat
runtime,Muleevaluatesexpressionstocompletethreetypesoftasks:
∙extract
informationthatitcanusetoprocess
thecurrentmessage;
thiscanbeusefulwhensetinsideanexpressioncomponentorexpressiontransformer
∙#[payload]
∙#[message.inboundProperties.propertyName]
∙#[payload.methodCall(parameters)]
∙#[xpath('
//root/element1'
)]
∙evaluateconditions
usingthecontentsofthe
currentmessage;
thiscanbeextremelyusefultofiltermessagesfrombeingprocessed
∙#[payload.age>
21]
∙#[message.inboundProperties.locale=="
en_us"
]
∙defineatarget,otherthanthemessagepayload,in
whichtostoretheresultofanexpressionevaluation;
typically,thisishelpfulwhensetinsideamessageenricher
∙#[flowVars.output]
Shortcut
Muleacceptstheexpression
#[payload]
asashortcutfor
#[message.payload].Thisshortcutonlyapplieswiththepayloadfield.
ThefollowingexamplesillustrateafewwaysinwhichyoucanuseMEL.
1.Useanexpressionto
extractdata
inorderto
decide
onacourseofactionbasedonthecontents,properties,orpropertiesofamessage.Forexample,arouter(a.k.a.flowcontrol)canroutepurchaseordersfordifferenttypesofproductstodifferentJMSqueues.
Intheexamplebelow,amessagecarriesinformationaboutpurchasesfromanonlinestorewhichcanbeeitherahardcopybookoranmp3file.Thefollowingcodeclassifiesthemessagesintodifferentqueuesbasedonthetypeofpurchase.
choice>
whenexpression="
#[payload.getPurchaseType()=='
book'
]"
>
jms:
outbound-endpointqueue="
bookPurchases"
/>
/when>
mp3'
songPurchases"
/choice>
2.
3.Useanexpressionto
extract
avaluefromthepayload,properties,orcontextofamessageanditsvariablesorattachments.Forexample,aconnectormightextractaspecificpieceofinformationfromthethecurrentmessagetouseasanargument.
Intheexamplebelow,expressionsextractinformationfromamessageandpasseachpiecetotheSMTPendpoint.
smtp:
outbound-endpointfrom="
#[flowVars.from]"
to="
#[flowVars.to]"
subject="
#[payload.subjectLine]"
responseTimeout="
10000"
doc:
name="
SMTP"
4.
5.Useanexpressionto
information,thenuseittoreplaceatokenwithanactualvalue.Forexample,aloggercanextractinformationfromthepayloadcontentsandplaceitintoaloggingmessage,asshownbelow.
#[payload]"
6.Ifthepayloadisanobjectandyoucancallamethodtoextractinformation,theexpressiontoextractmayappearasfollows.
#[payload.getLoggingInformation()]"
ExpressionsinMule
It'
simportanttoknowthatMELhasnotalwaysbeenthe
defacto
expressionlanguageMuleuses.Priortoversion3.3.0,expressionsinMulevariedinsyntaxaccordingtotheirspecificevaluator.Thus,althoughtheseexpressionssupportedawidevarietyoffunctionality,thevariationinsyntaxruleswastime-consumingtolearn.Thisolderstyleofexpressioniswritteninthisformat:
#[evaluator:
expression].Notethata
colonseparatestheevaluatorfromtheexpressionitself.
Mule3.3.0introduced
MuleExpressionLanguage(MEL),whichimplementsasinglesetofsyntaxrulesthatnolongerrequiresanexplicitlyspecifiedevaluator.Theevaluator,bydefault,isMELitself,anditcaninterpretexpressionsformerlyassociatedwithdozensofdifferentevaluators.MELexpressionsarewrittenaccordingtothefollowingformat:
#[expression].Notetheabsenceofthecolon,whichsignalstoMulethatthisisaMELexpression;
thusMuleevaluatestheexpressionusingMELlogicratherthantherulesofaspecificevaluator.
Mulecontinuestosupportboththeolderstyleofexpressions(whichspecifyevaluators),andthenewstylethatusesMELasthedefaultevaluator.Thoughbotharesupported,bestpracticedictatesthatyouuseMELexpressionsinyourapplication,takingadvantageofchangesandimprovementstosyntaxasMELcontinuestoevolve.
LearningMEL
Ifyou'
realreadyfamiliarwithJava,learningMELwilllikelynotbedifficult.Thatsaid,it'
simportanttocomprehendsomeMule-specificdetails
before
youlearnhowtoapplyMELexpressionsinyourapplication.
1.UnderstandtheMulemessagestructure.
BecauseyouuseMELtoactuponthecontentsofaMulemessageobject(payload,propertiesandvariables),youfirstneedtounderstandthebasicstructureofthemessage.Ifyouarenotalreadyfamiliarwithit,readaboutthe
Mulemessagestructure.
2.UnderstandhowtoseethecontentsoftheMulemessage.
Inordertobeabletoactuponit,youneedtobeabletofigureoutwhattypeofdatathemessagecontains.Isthepayloadanarray?
Doesthemessagecontainaflowvariable?
Whatinboundpropertiesexist?
The
MuleMessageTutorial
documentdescribesthetoolsyoucanusetoseeinsidethemessage,sothatyouknowhowtouseMELexpressionstomanipulatethedata.
Afterhavingabsorbedthismaterial,youwillbereadyandabletobeginlearningaboutMELbasicsyntax,andstartusingexpressionsinyourapplication.
GoFurther
∙NEXTSTEP:
Learnthe
basicsyntaxofMEL,ordiveinto
MuleApplicationArchitecture.
∙
∙Learnbetterbyexample?
Accessourcollectionof
exampleappswhichuseMEL.
∙Learnbetterbytutorial?
Accessthe
MuleMessageTutorial.
MuleExpressionLanguageBasicSyntax
Aflexibletool,youcanuseMuleExpressionLanguage(MEL)toevaluatemanykindsofexpressions,includingconstants,simpleoperands,operationswithmultiplevalues,ormethodcallsonobjects.YoucanalsouseMELtoperformregexorxpathfunctions.Thus,thoughthesyntaxisconsistent,theexpressionsyouwriteorcomeacrossinMuleapplicationsmaytakemanydifferentforms,dependingontheirpurpose.ThisdocumentaimstoofferinsightintothebasicsyntaxrulesforMELsoyoucanwrite,orparsethefunctionalityofMELexpressions.
ForfurtherdetailsonMELsyntax,seethefull
MuleExpressionLanguageReference
material.
∙Assumptions
∙BasicSyntax
oDefinitions
oBasicSyntaxRules
∙Examples
oMELAuto-Complete
∙DateandTimeFunctions
∙Tips
∙GoFurther
Thisdocumentassumesthatyouhaveread
MuleExpressionLanguageMEL
andhavestudiedthe
Mulemessagestructure.
BasicSyntax
Essentially,youuseMELexpressionsincombinationwithotherthingssuchas
operands
and
operators
todynamicallyreturnavalue.
Muleevaluatestheexpressionatruntime,andthemessageprocessorwithinwhichtheMELexpressionresidesusestheresulttoactuponthemessagepayload,propertiesorvariables.Forexample,youcanuseanexpression
inside
aSetPayloadmessageprocessortoextractausernamefromaninboundPropertyonamessage,thensetitasthepayload.Seeexamplebelow.
∙STUDIOVisualEditor
∙XMLEditororStandalone
Definitions
Afewdefinitionsbeforedivingintosyntaxrules.
Expression
InMule,anexpression
isastring,enclosedwith
#[].Atruntime,MuleusesMEL(asthedefaultexpressionevaluator)todeterminethevalueoftheexpression.
MELexpressionsfollow
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- Studio+Update+Sites11Mule Expression Language MEL Studio Update Sites11Mule
链接地址:https://www.bdocx.com/doc/19264043.html