基于mule的ESB解决方案

整理文档很辛苦,赏杯茶钱您下走!

免费阅读已结束,点击下载阅读编辑剩下 ...

阅读已结束,您可以下载文档离线阅读编辑

资源描述

EIP经典案例LoadBroker——MuleESB实践author:mythmoon@163.comVersion0.1(draft)转载保留出处读者背景:具有2年以上J2EE开发背景,熟悉Spring,Hibernate,Jbpm,Axis,Tuscany,Mule等框架,对EJB,Jms,soap,ws-*,BPM,SCA\SDO等技术规范,对ESB,SOA,通讯网关有一定了解,同时对底层Socket通讯协议HTTP,FTP等也有一定了解.当然对主流数据库也要熟悉,在示例中,使用DB2V8.1LoadBroker案例背景ObtainingaLoanQuoteWhenshoppingforaloan,acustomerusuallycallsseveralbankstofindthedealwiththebestpossibleinterestrate.Eachbankasksthecustomerforhisorhersocialsecuritynumber,theamountoftheloan,andthedesiredterm(i.e.,thenumberofmonthsuntiltheloanhastobepaidoff).Eachbanktheninvestigatesthecustomer'screditbackground,usuallybycontactingacreditagency.Basedontherequestedtermsandthecustomer'scredithistory,thebankrespondswithaninterestratequotetotheconsumer(ordeclinesthankfully).Oncethecustomerhasreceivedquotesfromallbanks,heorshecanthenselectthebestofferwiththelowestinterestrate.注解:AConsumerTalkingtoBankstoGetaLoanQuoteFigureI-1Becausecontactingmultiplebankswithaloanquoterequestisatedioustask,loanbrokersofferthisservicetoconsumers.Aloanbrokeristypicallynotaffiliatedwithanyonebankbuthasaccesstomanylendinginstitutions.Thebrokergathersthecustomerdataonceandcontactsthecreditagencytoobtainthecustomer'scredithistory.Basedonthecreditscoreandhistory,thebrokerpresentstherequesttoanumberofbanksthatarebestsuitedtomeetthecustomer'scriteria.Thebrokergatherstheresultingquotesfromthebanksandselectsthebestoffertopassbacktotheconsumer.注解:ALoanBrokerActingasIntermediaryFigureI-2LoadBroker分析设计DesigningtheMessageFlowWewanttodesignaloanbrokersystemusingintegrationpatternsdiscussedinthepreviouschapters.Todothis,let'sfirstlisttheindividualtasksthattheloanbrokerneedstoperform.1.Receivetheconsumer'sloanquoterequest.2.Obtaincreditscoreandhistoryfromcreditagency.3.Determinethemostappropriatebankstocontact.4.Sendarequesttoeachselectedbank.5.Collectresponsesfromeachselectedbank.6.Determinethebestresponse.7.Passtheresultbacktotheconsumer.Let'sseewhichpatternscouldhelpusdesignandimplementtheloanbroker.Thefirststepdescribeshowthebrokerreceivestheincomingrequest.MessagingEndpoints,sofornow,let'sskipoverthisstepandassumethemessageissomehowreceivedbytheloadbroker.Next,thebrokerhastoretrievesomeadditionalinformation:thecustomer'screditscore.AContentEnrichersoundsliketheidealchoiceforthistask.Oncethebrokerhasthecompleteinformation,thebrokermustdeterminetheappropriatebankstoroutetherequestmessageto.WecanaccomplishthiswithanotherContentEnricherthatcomputesthelistofrecipientsfortherequest.SendingarequestmessagetomultiplerecipientsandrecombiningtheresponsesbackintoasinglemessageisthespecialtyoftheScatter-Gather.TheScatter-GathercanuseaPublish-SubscribeChanneloraRecipientListtosendtherequesttothebanks.Oncethebanksreplywiththeirratequotes,theScatter-GatheraggregatestheindividualratequotesintoasinglequotefortheconsumerusinganAggregator.Ifwemodelthemessageflowusingthesepatterns,wearriveatthefollowingdesign:注解:SimpleLoanBrokerDesignFigureI-3Wehavenotyetaccountedforthelikelyeventthateachbankmayuseaslightlydifferentmessageformatfortheloanrequestandresponse.Becausewewanttoseparatetheroutingandaggregationlogicfromthebanks'proprietaryformats,weneedtoinsertMessageTranslatorsintothecommunicationlinesbetweenthebrokerandthebanks.WecanuseaNormalizertotranslatetheindividualresponsesintoacommonformat:CompleteLoanBrokerDesignFigureI-4扩展:核心技术与实现方案Sequencing:SynchronousversusAsynchronousSofar,wehavedescribedtheflowofthemessagesandtheroutingandtransformationpatternswecanusetodescribethedesignoftheloanbrokercomponent.Wehavenotyetdiscussedthetimingofthebrokeroperation.Wehavetwoprimarychoices:Synchronous(Sequential):Thebrokerasksonebankforthequoteandwaitsforaresponsebeforecontactingthenextbank.Asynchronous(Parallel):Thebrokersendsallquoterequestsatonceandwaitsfortheanswerstocomeback.WecanuseUMLsequencediagramstoillustratethetwooptions.Thesynchronousoptionimpliesasequentialprocessingofallloanrequests(seethefollowingfigure).Thissolutionhastheadvantageofbeingsimplertomanagebecausewedonothavetodealwithanyconcurrencyissuesorthreads.However,itisaninefficientsolutionbecausewedonottakeadvantageofthefactthateachbankpossessesindependentprocessingpowerandcouldbeexecutingrequestssimultaneously.Asaresult,theconsumermighthavetowaitalongtimeforananswer.Synchronous,SequentialProcessingofLoanRequestsFigureI-5Theasynchronoussolutionissuesallrequestsrightawaysothateachbankcanstartprocessing.Asthebanksfinishthecomputation,theyreturntheresultstotheloanbroker.Thissolutionallowsforamuchquickerresponse.Forexample,ifallbankstakeasimilaramountoftimetoproducealoanquote,thissolutionisalmostntimesfaster,wherenisthenumberofbankswearedealingwith.Theloanbrokernowmustbeabletoaccepttheloanquotereplymessagesinanyorder,becausethereisnoguaranteethatresponsesarriveinthesameorderthatrequestsweremade.Thefollowingsequencediagramillustratesthisoption.Theopenarrowheadonaloanquoterequestindicatesanasynchronousinvocation.Asynchronous,ParallelProcessingofLoanRequestsFigureI-6Anothersignificantadvantageofusingasynchronousinvocationviaamessagequeueistheabilitytoc

1 / 24
下载文档,编辑使用

©2015-2020 m.777doc.com 三七文档.

备案号:鲁ICP备2024069028号-1 客服联系 QQ:2149211541

×
保存成功