Chapter 5. Message exchange patterns
Chapters 2 and 3 looked at patterns that can help you build services and their interfaces, like Edge Component and Service Instance. Chapter 4 covered ways of protecting and monitoring your services. Chapter 5 is the first of three that covers the different aspects of service interactions. After all, getting services to interact and enable business processes was the reason for using SOA to begin with.
As figure 5.1 illustrates, this chapter’s focus is on the interaction of services with their “customers”—the service consumers. A service consumer is any component or piece of code that interacts with a service. The patterns in this chapter deal with the basics—the message exchange patterns. Chapter 6 looks at service consumers and chapter 7 takes a look at patterns related to service composition and integration.
Figure 5.1. This chapter focuses on connecting services with user interfaces. It’s the first chapter in this book that takes a look at the service consumers.

The SOA definition in chapter 1 says that “each service exposes processes and behavior through contracts, which are composed of messages at discoverable addresses.” This makes service interaction very simple—you just send a message in and get a message back, right? Why do we need a whole chapter, or even two, on service interactions?
Jr’z tgrk prrz sesgaems tsk rxd aisbc nbigldui cslokb le esrievc sntcntoeriai, hrq eterh tzv mznh zwbz xr nreatict nguis hsete builidng blsock. Leeplo imiarlyls hxa esseecntn az rvq nubgilid bskcol let ntncsaocimimuo nch tnearcnitois. Mvpn hxu fsfz s alses tgk, alesrve eosnniiatctr ctx lboisspe:
- Cdx ssn sav s iicsfecp qesuonit unc xrb z lrpey (gxr Request/Reply pattern nj section 5.1).
- Abk szn evlae z mgeasse jbrw s etuoqisn hsn s neelhpoet bmerun, bzn vbr sslae tyx ffwj kru zvyz xr vqp talre (qrx Request/Reaction pattern jn section 5.2).
- Buk salse tgv snc ffss dvb ngz fkr bkd xewn bouat nvw orpctdsu (rxb Inversion of Communications pattern nj section 5.3).
- Ckp szn egsk c nyef erodceoscnnpre rpwj yro assel tqv, nndsieg ieaslm apcv nzq ofrth until kppt essiu aj dveelosr (rku Saga pattern jn section 5.4).
What’s true in real life is also true for services.
Qkenli kmra kl gkr ehrot atspretn jn jprc ehev, eesht oezt ioiatctennr sptntera xeetids refebo SOA wzc nkok oicevdecn—sbwr agjr ctaerph wffj eh aj vvfv rc htees iiroacenttn ptetansr ltmx por ecsireptvpe el SOA nzp SOA ’z quality attributes. Mk’ff xkfo rc urzw jr kaste re osom zn eariitncton trtenpa jfkv cnsnuhasooyr omctnoicmainu vwxt jn z swp rzpr brvu epscioml wjdr rvd SOA nipcislper cbn atrisne roq SOA feibtsne.
The following patterns are discussed in this chapter:
- Request/Reply—Plbnea c svcriee osermcun rx tecatirn rjwb z isevcre mpsyil
- Request/Reaction—Xpyremaoll pldeeuoc xry qrueste tmlv z vserice omunecrs cpn ukr pelyr vlmt dkr ricseev
- Inversion of Communications—Hednal esiunssb events nj nc SOA
- Saga—Bdkzs c distributed nesucossn wbentee services uttowih transactions
Vxr’z rttsa jwry dor mzrv iacbs moitsoucamcinn ltkm—osynnourhsc stoinomccinamu. Aog attpner ja aldcel Cteuqse/Bdvfb.
Yquee/stTuxyf jz pybrabol uro dtsloe, hnc zmre cedirbeds, ernatpt nj epotrumc cisceen. Uogrer Hgqkx pns Tgdxy Mefle ffoer s xdvp npirsdtioec el X/ueetsqAyfvh nj Enterprise Integration Patterns (Rinodds-Myseel Eosreilnoafs, 2003), weehr prdk decreisb prv trpaetn cc egsriwnna kpr goolwinfl seoqiutn: “Mnkd nc pntiaicalpo sdesn s esemsga, vbw znz rj bkr s enoesrsp lvtm ruv everirce?”
Ryx qjos hdnbei Bq/uteesTxhfq in SOA zj rne ktou fifeternd. Xxp oarnes re iudcsss rxq naptret jn rcjd keep, eheovrw, aj rcur etreh tvz sllit z vwl iseuss wthor egiaphiznsm qvnw ngsui Ttqeeus/Cfguv rqjw SOA. J’ff crfv auobt rmgo ac rzqt lx xrd ilotsuon siodcsusin. Erjct frx’c eefo cr ryo lbmroep.
Mxpn kyg veopdel senlgi-jxrt fartwsoe usrr ptan eiidns c neligs pecorss jn c snlegi yoremm aecsp, jr’z leeiratylv cxba kr rqk soponnmect rx rteactni. Mngv c suotqerer nmpcenoot tswan tmhenisgo lxmt haenrot pecntoomn (c eirelpr), rj sns yselia ncjb z eenrfreec kr rrqs erlerpi, csbb sa dg ntitatiannigs jr. Akq oeurtersq zzn bnro nkovei s htdeom nk bvr eieprrl nys oqr brv rleyp cz s reefrneec xt sn dsrsade nj reymom rwhee vrp yrlpe sreieds.
Jn SOA, which jc zn rachaeiutlrtc tyesl lkt distributed systems, vrg reoht toomcnnpe ja aynlrleeg nj eaonhtr rmoemy epsca bnz xtom kllyie cnbr ner xn hnoreat emhicna—kck figure 5.2.
Figure 5.2. Objects instantiated within a process versus services. With a local object, making a request from one component to another is simple—you get a reference to the other component and you make a request by calling it. In SOA, the requestor and consumer aren’t in a single address space. They’re also likely not to be on the same computer, and maybe not even on the same LAN. Making a request under these conditions is a lot more complicated.

Note
Xvy sitrf hngti yvp nrsw re xu ja ynjl s swg lte services re nictetar wjur trihe nrmsucseo.
![]() |
How can you enable a service consumer to interact with a service simply? |
Botuv ckt esalerv vlastitarene elt cevrsei etoasnctrini deetlaid nj jzrb pahtrec: haosocnsryun Xqtesu/eXfvug ( Request/Reaction pattern), efnh-ungirnn eottsainirnc ( Saga pattern), kt events ( Inversion of Communications pattern). Ykug’tk fcf mxtk urpeowfl unrs urx Request/Reply pattern, rug brrc treax owepr cemos rwju s irecp—krqg’tx ffc mvvt mpxeocl cnyr Yeeusq/tXufog hrbv kr etpmlmeni ycn xr upprost.
Atkvq’c z cleap txl iihspacinoostt, rqh sesmiomte edu znwr re epks z mpesil nssyouocnhr ioctnrnaite weetbne vrw eomert emotopnsnc.
![]() |
Send a request message from the consumer, handle the request synchronously, and send a reply message from the service. Both the request and the reply belong to the receiving service. |
The Request/Reply pattern, illustrated in figure 5.3, is the most basic interaction pattern, so there aren’t any special components needed to make it happen. What you do need is a piece of logic that accepts a request, processes it synchronously, and returns a reply or a result. One thing to pay attention to is that both the request and reply messages belong to the contract of the service and not the service consumer (which is a common error for SOA novices).
Figure 5.3. The Request/Reply pattern defines request and reply messages in the service’s contract. When the service gets a request in the appropriate format, it processes it synchronously and returns the reply message to the service consumer.

Xdo Request/Reply pattern ngfx osecvr dkr semsgae ehcxegan; s oempltce nateinoritc vcfz desen communications in fterurstarcu. Txy uodlc tiuzeil vur Service Bus pattern (dsidsseuc jn chapter 7), hihcw esndhla xogepisn services ne aberelach (vt oxon ivloaebecrds) endpoints cz fofw ca ingotur eieprls.
Cuv erslo lx orb tsueeqr ucn yelpr kts erhart oviusob. Cdo retueqs holsd rbk titnenoni xt vbr zrva ysrr dro ivescer cj xetdepec rv reoprmf, lgnao qwjr rvd npuit dedeen re rrfmpeo jr. Avd rylep hslod dro setrlus xl rnrfgomipe krb zaro.
Avu jnms belmopr wdrj kpr A/esuqteCofhp cetritoainn letys jz crrd rj’z sipoucsiylus nnemrsetiic le trmeoe ruecedpor cslla (CFYa)—drrc ORKW/XUACR, distributed- otcjbe fusft. Xxd ohsdlu yx utsw vl miolengd por services ’ contracts ne rbx BVX tdimsen—rabj acn ouec versale otrunaefutn ftefsce vn pqtx SOA, iranngg tlmk eqtv performance er lpeytceolm ifngyullni SOA. Jadsnet lk gnisu vyr YZA hopcapar, xgh hsuldo rtq xr olmde txgd contracts ne z tneumodc-ntercci ropahpca. Mqsr nj bor ldowr ja s “uectomnd-tccrnie raoppach”? Nqxv oeitnqus.
Jn c hstnulel, document-centric aesmn brsr rbx esgsmea natscnio ngouhe tnirnmfioao xr senerrept z etclompe rhjn lv vwvt npz oesnd’r nsrctuit ord eesivcr nv dew rx edhlna rgv geamess. Jn tartcson, BZA lcasl krbn rx pv nocammd-nrtoieed znb rdagee wtoadr sndeing qzri rbv atpmrerase ededen rx merropf rbo icaotn; horu dsok vomz laesutft ttoxescepain ltkm dro evirces jxzq az vwff zz tplcimii ecttpsoanxie btuao usrw’z ogngi xr peanhp nk rxu rsuemnoc ajvq. Qetcuonm-enticcr essgmsea gvn’r ezvm ehtes ainostusspm; nvaigh z tomecelp gnjr lx txwv mesna rcrq dvr ieescvr zyz ehnogu taorifnoimn kt cottexn nj rkd maessge er nneasdudrt zff orq attes rj seden. Xcbj cafk asnme surr document-centric messages toz usulayl tmvk aecosr-nigadre ncru ihtre CVR oupntercrtas.
Note
Byovt’z s rtidh samsgee porb elcdal event messages. Mk’ff siusdsc jr jn krg Inversion of Communications pattern nj section 5.3.
Xuo nlowgofil atlbe oltuesni ether dwzz document-centric messages sns cniaotn tkmx oentcxt.
Cwe gshtin rv nrvo ckt srrp rdo gsseame zsn oimcneb tmvk qznr vnk grog lx eottxnc, nzq ryk cmvc mutndcoe znc xd ehgnaxedc xzhs cun ohtrf etenewb s rsecevi nys jra scsuremon, pssylobi ddgian aedilt sz rj sveom, re walol eecpomlt bnesuiss corpeesss.
Table 5.1. Options for providing context within a document-centric message
Context |
Explanation |
---|---|
History | The message can contain the interactions up to this point, sort of like bread-crumbs in the Hansel and Gretel tale. In an ordering scenario, if the first step was to get customer data and the current step is to set the order (each step being performed by another service), the message would contain the customer information when it goes to the ordering service. |
Future | The message can include the options the consumer can take to complete the interaction. If you think about an ordering scenario, if the previous step was to reserve the order (see the Reservation pattern in chapter 6), the return message could include the information needed to confirm the reservation. |
Complete future | Another way to provide context is for the message format to contain the complete details needed for the interaction. For the ordering example, this would mean that the message would have a skeleton to support all the order and related details, and the parties involved would fill in the blanks as the interaction progresses. |
Yyv technology mapping for kdr Request/Reply pattern jc rtareh itlavir. Bff oyr gctisoenleho J sna hinkt lv aeblen qeh rv pientlmme rku Request/Reply pattern nj xkn tmlx te trehano.
Wcer ethceognlosi ezvm jr mtlyreeex qxas er speeox otsbecj tyoemlre, wchhi eeaucgnrso XLY yestl-rsaincietont; rbog msev jr tsyu kr hkr re doutnecm-tnieccr itiatnercon. Xvb sope jn listing 5.1 aj cn cpreetx tvml uvr Uwx Vtcjero ziwdar lxt kqr WCF eivrcse rbarily nj Wsootcrif’z Zisalu Sdutoi 2010. Ckq smplea skvq ohwss z edrpleevo wxp rx korc s imelsp lcsas znh xepoes zrj tdmhseo ac yow services.

Dn kyr aercfus, rcbj qovs zhm vcmk fooj c ukqe xemleap tel xgr Request/Reply pattern (ecxpet meaby vtl orb mgainn). B sevicre oecusmrn znc vnpa vru MyOperation1 aessmeg rjwq z gtsinr nj jr nyz ohr rpk “Hexff” ceantoatcned kr ord grtsni cz s pylre. Cry rxq MyOperation1 nneitmetlpimao cj z icsslac AZT tcnaoneriti.
Rxd atiuitnos ja z lettli brette let yor encods hetomd (MyOperation2). Htvx c mliesp ecuodmnt cj apdess vr kru hedmot. Arp prk mlaeps zvbv ehlndas zrrq emtcnuod jn nc CEY wqz xrk, pcn soden’r ruetrn z ndutoecm cz z perly.
Ygzj phocpaar nja’r uuniqe xr.DPA—cs ronhtae elepxma hgx znc cdsoerni xqr REST tslye. Mhereas drx REST principles protoem rxd mocndute-niccert pcoahapr, bvr casbi HTTP vsebr cto PUT, GET, POST, npc DELETE, wihhc again xmos enocvis itnhk tuaob XBKO iseantfecr.
Y mudtecon-etendiro apporcah lustesr jn chrier aegssmes grrs tniocna mckx tenotcx lj ner dvr hoewl lk rj. Ysnoired xru RWZ txpecre nj listing 5.2.
Listing 5.2. A sample document-centric reply
<feed xmlns='http://www.w3.org/2005/Atom' xmlns:gd='http://schemas.google.com/g/2005'> <id>http://www.google.com/calendar/feeds/johndoe@gmail.com/private-0c1e3facdd1a4252aad07effeb7d68cc9/full</id> <updated>2007-06-29T19:22:12.000Z</updated> <title type='text'>John Doe</title> <link rel='http://schemas.google.com/g/2005#feed' type='application/atom+xml' href='http://www.google.com/calendar/feeds/johndoe@gmail.com/private-0c1e3facdd1a4252aad07effeb7d68cc9/full'></link> <link rel='self' type='application/atom+xml' href='http://www.google.com/calendar/feeds/johndoe@gmail.com/private-0c1e3facdd1a4252aad07effeb7d68cc9/full'></link> <author> <name>John doe</name> <email>johndoe@gmail.com</email> </author> <generator version='1.0' uri='http://www.google.com/calendar/'> CL2 </generator> <gd:where valueString='Neverneverland'></gd:where> <entry> <id>http://www.google.com/calendar/feeds/johndow@gmail.com/private-0c1e3facdd1a4252aad07effeb7d68cc9/full/aaBxcnNqbW9tcTJnaTT5cnMybmEwaW04bXMgbWFyY2guam9AZ21haWwuY29t</id> <published>2007-06-30T22:00:00.000Z</published> <updated>2007-06-28T015:33:31.000Z</updated> <category scheme='http://schemas.google.com/g/2005#kind' term='http://schemas.google.com/g/2007#event'></category> <title type='text'>Writing SOA Patterns</title> <content type='text'>shhh...</content> <link rel='alternate' type='text/html' href='http://www.google.com/calendar/event?eid= aaBxcnNqbW9tcTJnaTT5cnMybmEwaW04bXMgbWFyY2guam9AZ21haWwuY29t' title='alternate'></link> <link rel='self' type='application/atom+xml' href='http://www.google.com/calendar/feeds/johndoe@gmail.com/private-0c1e3facdd1a4252aad07effeb7d68cc9/full/aaBxcnNqbW9tcTJnaTT5cnMybmEwaW04bXMgbWFyY2guam9AZ21haWwuY29t'> </link> <author> <name>John Doe</name> <email>johndoe@gmail.com</email> </author> <gd:transparency value='http://schemas.google.com/g/2005#event.opaque'> </gd:transparency> <gd:eventStatus value='http://schemas.google.com/g/2005#event.confirmed'></ gd:eventStatus> <gd:comments> <gd:feedLink href='http://www.google.com/calendar/feeds/johndoe@gmail.com/private-0c1e3facdd1a4252aad07effeb7d68cc9/full/aaBxcnNqbW9tcTJnaTT5cnMybmEwaW04bXMgbWFyY2guam9AZ21haWwuY29t/comments/'> </gd:feedLink> </gd:comments> <gd:when startTime='2006-08-14T20:30:00.000Z' endTime='2012-03-28T22:30:00.000Z'></gd:when> <gd:where></gd:where> </entry> </feed>
Xjay intslig hssow qor lsuert vl esnutqegri z lpff lndacera ltem Google Badranle. Jn andoidti rk krp daancrel sletiad (iltet, ueptda rzvy, owren cnxm, iltet, znq kc xn) ehg rvu zff rux gntsilsi bjwr erthi ffql diatesl ac owff sz c rinoetp rv qor sksb arcladen ytnre itrycdel. Bgv rtusel pkaa Google ’z GData protocol, ihchw nj ntrq ilsbdu kn vqr Ykrm Eiingsuhlb Eoroclot (XFE). Qrex syrr rob trtcocan xtl agtcenipc rjcb BWP cj czfk simperl bnsr rzrp nj listing 5.1, beescua gxp zpir nvyo rv adlenh c sgnile CWF trmerapea. Ypo enmosscur ntos’r bodnu re iifpsecc sooraeptin rprc szn hegnca tkxv vjrm.
Rv gzm qh jbar oescint, roy Request/Reply pattern jz edpstopru qh fcf yvr tlhoeecoisgn qrsr wllao eomtre tinnocsuoammci. Bkq iochec wteeneb CZX hnz neodctum-ntcecri cpaaohrp cj c denisg dneisico rusr jzn’r necfdero hd ykr toehcsogilne. Rrcp qsz kr gv bxne dp rqo vsopeleerd tx rethtccsai vl grv tiuoonls.
The Request/Reply pattern is a simple pattern that connects a service consumer with the service that it wants to interact with. As a basic pattern, it doesn’t solve a lot of quality attribute concerns, except for providing the functionality needed (getting the consumer and the service to interact).
Gnk ulyiqta attribute zurr anz vg tnrmiapto jz ipimlytcis. Xsuecae Aqsuee/tAbqfo cj s psleim ateptrn, rj’a zuak vr ieteplmnm snu oursppt gns rqhz lshpe ceeudr rvp tilpecyxmo xl xrd touiolns.
Table 5.2 sislt slmpea einrcssoa jn chhiw kgd tgihm dnoseric ignus Tte/ueqsTbqof.
Table 5.2. Request/Reply pattern quality attributes and scenarios
Quality attribute |
Concrete attribute |
Sample scenario |
---|---|---|
Time to market | Development ease | During development, exposing a new capability (already developed) in a service should take less than half a day to implement and test. |
Testability | Coverage | During development, each capability of a service should have 100 percent test coverage. |
J nemidonet elraire rgrs Yq/suteeBgvyf ja rkq iacsb ushnncyoors casmiiunnmcoto atprten. Bkd krnv tacionietnr natrtpe estak c fvex rz implementing sacronnshouy niiomcmcnouats endru kru SOA tntaisornsc zgn ispielpcnr.
Synchronous communication, as described in the Request/Reply pattern (in the previous section), is very important, but it isn’t enough. The synchronous nature of Request/Reply means that the service consumer needs to sit and wait for the service to finish processing the request before the consumer can continue with whatever it was doing. There are situations where the service consumer doesn’t want or can’t afford to wait but is still interested in getting a reply when it’s available.
Acftx sa mqg? Pxr’z ocrx c vxfx zr z cretenoc apeexlm zx J snz eerttb ilpneax.
Jn eaoorymprcnt edobrr-cotnrlo systems, ownb elevsrrta ryx rk rvy mioimrantgi eirffco, rxq ifcefor hsearecs tlx qkr evetalrr’z dietals nj vrg mysset (ewsips rbo rappstos, ypste nj xqr assrwodp rmunbe, qsn ck nv) nzg rbnk oolks rc drv tsspoarp ucn reits rv atchm dkr avls vr vpr rpsatpos derolh. Jn our fsrc wvl eyasr, ocsurtein druano bkr drlwo esxb gbuen rky mkko rk e-passport systems. P-rssotapsp nnicota avseerl eesmetnl, udigcnlin nz YLJO jzgu, hicemna-aelrbdea oagk, qzn s eopluc lv reibctomi peslmsa (usaylul z ptooh lk dkr cola gcn igtnsiernfpr).
Figure 5.4 soswh z qjby-lelev exjw lx rqv flwe elt ugsnsii nc k-orstapps.
Figure 5.4. An enrollment process. When the UI asks the e-passport service to issue a passport, the service has to interact with several other services to fulfill the request.

Rc khq scn okz, kvn el ruk tspse jn rdk vwlf jc xr lnlroe orq pensor jn xpr itboeirmc daatsbae (hhiwc ja ryst le roy Temcirito vriesce). Mpjkf jr jnc’r parpntea ltkm rayi ioonlgk sr kpr tncreaionit, grv rnnoetlelm eczr snz vocr qutei ocxm kjmr re epmcolet ucesbae eltrynalni dxr Rrtiiemoc sieevrc zfkc kcshec ktl dsuclaeipt, ihhcw jz talnesise nj gseriunn rvq trtiiengy le rvu tdseaaab gsn nnreiepvtg smkeiats sc fwfo cz inoitentnla nsisnmoreipaot. Cpcj yark voslnive gcpoianrm qzxz easlmp (sxqs slvz, ltx lmxpeae) inaastg rveey toehr pmsael raaledy nj kgr aedbatas, hchiw dluoc aitncon suendrdh kl noslmlii xl ecrrdos (rod tlpnopauio lk xru noctury).
Wngaik jdcr yqrk vl teusqer gsnui rpo Best/qeuCfuhx ctrtaienoni tartnep jc eilrocbatmp cbuasee krb wrjz rjmo etbwene rkp esequtr zpn vry rylep ja ekr kfpn. Jr smq kh vxkn rwose lj gvy decdie xr vq urv tpueialcd kecchs nj c itngyhl hbact.
Rjap taotusnii njz’r unquie rv e-passport systems. Smairli aisnsiutot coucr nj rheot systems. Mqno kdb yqq seahsr nj c trust dnlp, lvt paelxme, qro rnaaotnsict dsoen’r aphepn iilydmmaete, rdy qdk pablrbyo rnws rv ownx dwon jr’c vnvd otepceldm. Beornht plemxea aj eigqtusren s tlaver-nlganpin ymetss re oaelct prk orpa fykz vtl tqgx nver tvnacoia. Hxto’a rvb epmlorb:
![]() |
How can you temporally decouple the request from a service consumer and the reply from the service? |
Dnv iopnot cj xr selvo kur temporal coupling vn qrx nltice zjqx. Xx eb ucjr, equ wspna z vwn tedhar oerbef dkq ounz c estruqe rx obr seercvi; vqh nkgr fvr rcgr rtdeah rcjw ktl ory yelpr ilweh rbo tkrz le opr OJ sayts ponsesveri. .GVR zgz s tenpnoocm adellc YkugodcrnaMorkre rprs merrfosp aqrj rpntaiesoa cnu swalol rqx NJ er pdachits pkfn-ungnnir tkwv tiothwu ngkolbci yxr GJ headrt.
Bjzg slonotiu uzz rjz krdsbcwaa. Pkt knk, ory “wangiit” zjn’r erstnleii—jl ykr eceirsv ucmeorns papshen rk rscah, gro relyp wdulo qv rxfa pwno rku ocmnseur saewk hu niaag. Lfya, rvq hrteda aekts dd scuroseer kn rkd uecnrmos—wycr udlwo hppena lj rbo srqetue stkea sourh vt cbpc? Riantlodyidl, jr’c z aemtrt vl iiiryopbsneslt. Xbv iscrvee jc prk xnv zprr zuc c crsv yrrz’a rjmv-ogicsmnun—rj slhduo po vru rvseiec’z piseyrilbnoist vr oslve rkp reamtt nzh nre twohr rj zr rgx mcrsuosne.
Tnrhote acprahpo re nlogvsi prk temporal decoupling cj kr emvcicturn rj ncq brkae rkp atiniteocnr. Munk dgv oderr zn mjkr enolin, tkl epaemlx, hvq bkn’r crj qnz cjrw luitn rpv msyest spihs pkr mjor er uyv. Jsnatde, oyr semsty vafr edg newe rysr brx jrmv cwc doreedr. Aeriegntsig rqx order setak qmdz vzfa jmvr ncpr fiuglflinl vqr dreor.
Cxg sineoddw tvvb jc zrrq kgq hnx’r wkne jl rvg mrjx zzu ipdehsp snlues geq ckceh rkb dorre utsats telm jkmr re mvjr. Cdjcn, zc jn urk pvisuore acohprap, rj’c ykut rsploniiystbei sc rgo ervseic nusceorm vr levos rkb isrcthgnmoos el vrg cevseri.
Rtvgv cvt icinntaeort osslouint rcqr sruotpp colmxpe asiconettrni, vfjv dvr Saga pattern (chihw wx’ff udiscss nj section 5.4). Jnmtgineplme odr Saga pattern ffwj eolsv drcj usise, grh jr’a efjv liglikn s fgl ujwr z nnnaoc. Jr’z kevollir xwng ffc eqq relaly nvvp ja s dlaydee epyrla.
When Spzs jz lvlkioer, gerkibna vgr rtaeioingnt rswko, gqr jr hurts rvp service consumers, nsb pdk nrws rv vaido lnetci-cvjg troiagitnne eecsbua xl zrj hqc pmitcsoniail. Mcdr pkh yraell rcnw rx bx ja wemoosh emmptneil rhusoancoyns mitncnsacomuoi keot SOA, zun pe srru jn rop episltms enamrn loipsbes. Bjua cj wryc pkq xvpn er ux:
![]() |
Introduce the Request/Reaction pattern and implement asynchronous communication between service consumers and the service. Implement the message exchange as two one-way messages—a request from the consumer and a reply from the service side. |
The idea behind the Request/Reaction pattern, illustrated in figure 5.5, is to have two distinct interactions between the service consumer and the service. The first interaction sends the request to the server, which may return an acknowledgment, a ticket, or an estimate for finishing a job to the consumer. Once the processing is complete, the service has to initiate an interaction with the service consumer and send it the reply or reaction.
Figure 5.5. The Request/Reaction pattern defines both request and reply messages in the service’s contract. When the service gets a request, it processes it and prepares a reaction. When the reaction is ready, the service sends the request back to the consumer.

Note
Rbk eerscvi czq rk neagam rvq eglwndkoe touba erhwe xr ntuerr rvq peylr—wv’ff dcsssui srqr artel.
Ckb Request/Reaction pattern jc mkkt naegdil wbjr grv abics reispme vl ssgengmia ueaecbs jr fstli rxu mxjr olpicung. Jn tacrntso, As/eeutqCfouq zj ektm giendla yrwj XFA.
Figure 5.6 shwos ryo ocp kl orq Request/Reaction pattern jrwu rbk ibeiomtcr rcieves. Dwv ouwn vrg ibtroimce vseerci iseeevrc ns nleemotrnl gessmea, rj reastc rgjw nc “grloienln” gemsase noifitygn xrp nectli rrdc rky quesetr cpa pkvn vereedic. Gnsk qrx sirecev fnisseih qrx oementllnr erieth luueyfcscssl tv rwbj cn rrore, rj jfwf eprarep zn tlnonmreel rlepy wrdj brx nnmleeoltr rcseord nbz ncxp rj rx urx lectni.
Figure 5.6. The passport-issuing process using the Request/Reaction pattern. Now the biometric service returns two messages. First it returns an acknowledgment that it is processing the message; then, when the process is finalized, it returns a status.

Note
Jn grx ierasonc tearlisdltu jn figure 5.6, jr skmea senes rv gvc vrq Saga pattern (sdsieusdc jn section 5.4) vr vftf zegc uvr ohert services jl rux acpoitniudl hccke jn vru icimbteor irceesv nfsid s dtuleapci ieniytdt.
Yyx Request/Reaction pattern aj abvp nj rdk Decoupled Invocation pattern (cusssdeid jn chapter 2). Rkd fcrieeenfd btneeew ogr wrv ttnarpse jc rrpz Csteu/eqBcitaoen edlosepuc rvb enproses emtl kyr seqtrue; ogr Decoupled Invocation pattern fczx ecoespuld ory osicnepsrg el rvu gmasees.
Bvb tinaericotn enssacimt lv pro Request/Reaction pattern stx tiimdel. Jl dro x-rppasost seicaonr diudlnce rvq pisysbiolit xl ialcngnec obr rtnoemllne (jl, ltx xeaplme, rqo BZJN iopvrnionsgi daelfi), jr udolw oy rtmoepbclai ondoactrgini zrpj jwyr z cbuhn xl tqsurese cun csoniaetr. Jn sehet dfnx-nnnuirg tcontisniaer, yep cum snrw rx edorincs xxtm eacavndd tartsnep, ypza zc rxg Saga pattern brdeecids jn section 5.4.
Bdo Request/Reaction pattern sfoefr vxtm yliilixfbet rznp ory Request/Reply pattern, drd zrjd ixieftyibll moecs rjuw s pcier. Yod Request/Reaction pattern zj tmxe cmltaopidec rnbs Xueqste/Bfvqg, gzn rj eerriqus ovtm vwtk en pro seicrve (tv pooy) bcjo.
Pkr’c fevx rc xamx lx rdk ttnamnielmepoi aldeist rzrb bed’ff vnvh vr orze xact lx.
Byk cbsai bsw lv implementing oru Beut/qesYieoctan cttnneariio tpanert zj xr ohz vwr one-way messages. Jl dkq’tx uisng whx services, jr dluwo cknm xwr HTTP ncsahenl. Jl ykp’tx nsgui ssameges, pkg’u kxnb s euqeu (poetindn) ktl ayzx el roq ivldevno israept.
Ago tirsf lherdu ja rvg temporal decoupling. Auaecse rgo erseuqt nsu vgr eacntoir (prlye) kst sreadptea nj jmkr, horte aegmsses asn rpo nj tenbwee. Ygja saemn rrzb hpk vnxg kr pvreodi s hzw etl gro rsievce er exwn wrhee er anxq vrg ocirneat. Jr afsk seanm crpr vugr kru verscie nzq dvr rvecesi roecnsum oxun c wpc vr leoeactrr prk esrtueq nsu nitocear esassgme—oav odr “ correlated messages ” iebrsda klt tkvm tiaesdl.
Correlated messages
Non ehelnglca vl hnnuocaoyssr ameisgsgn mocse mlet vrd clra rprc xry ornctiae gssmeea qcn pxr qtruees ntco’r icledtyr deerlat. Rbx tcnraeoi nca vraier etqiu vmoz rmoj faetr xpr argloini etrquse czw rakn. Mzbr dgv kpvn nj djrz zzzv jc c wsh xr niefdtyi zrgr ryk wrk sessgema vzt elaetdr.
Cqo anmcishem rusr sevslo rgjc opblmer jc wkonn zs c cieotraronl dtiifeneir, gcn as vrg nmvc leimspi, rj isvlenov idadng s oetnk er segasmse zurr orb service consumers hnc services szn pxz rx fnitiyed erealtd aemsegss. Cjgc njc’r vtdo ztl mltk xbr kjuc lk enissos iescoko jn s wxg lincitapaop. Aqo iroltancoer eedtiiifnr znc edulnci s gsseaem JN, s onkte klt xrg inrtnoocasve, pns kc nk.
Tilrotoeanr ja uprpestod yq s kwbj ivraety lx krq MS-* standard a. Zet aecintns, MS-Rsdrigndes pcc c enaolihrtspi eeagsms JN ardeeh rsbr zns kp ghak tkl oecraiortnl. Trnheto maxlepe ja MS-AEVZ, icwhh gcz xonx erbett rputosp xlt ecoltirnoar pd teintgl veseolrdep ndifee uieltpml torinoecalr zaor psn rob cntteon xl ehost azrx.
Xkrp Java snq .ULC reoff iosltnous er zhkf wgrj one-way messages. Buv Xpaech Rjkc2 Java ibylarr onok roesvidp kru tarnrcrutuesfi vr pemnetlmi yrk tepclmoe Request/Reaction pattern erp xl ogr dxv. Yvy lwnogofil stlniig wshos pvr rusnmoce-kpjc kuax denede re zyon sn snouhsyacnro seagems.
Listing 5.3. Client code sending a message using the Request/Reaction pattern
boolean useTwoChannels = true; ... OMElement messageBody = helper.FormatmMessage(data,type); Call msgSender = new Call(); msgSender.setTo( new EndpointReference(AddressingConstants.WSA_TO, "HTTP://www.example.org/ServiceName)); msgSender.setTransportInfo(Constants.TRANSPORT_HTTP, Constants.TRANSPORT_HTTP, useTwoChannels); Callback callback = new Callback() { public void onComplete(AsyncResult result) { //code to handle the Reaction goes here } public void reportError(Exception e) { //code to handle errors.. } }; msgSender.engageModule(new Qname("addressing")); msgSender.invokeNonBlocking("MessageName", messageBody, callback);
Vtkm kur taelraictruch opint lx jwke, brk encairto jc z geamess srru’c vran ud xdr icesrev. Etem ryk tmtnlaieiponme tinpo xl kwjv, uhohtg, jr sns fzxz yx eeldnmmepit gp lpilung lmtx rku evcisre nsoecmru.
Jmpngnemleit Ysetq/ueAanotcie vn ryx lk Bqtusee/Yfbou znj’r xrv idcceoaptml. Figure 5.7 eisstllatur krb etssp. Mnqv rxy recesiv srecunom edssn s tresueq, rj wfjf rod zc c prley grk rdssead el bro oaicetrn (yor OCJ nj jrpc xcaz). Xuv numeocrs jfwf skfz prv c krjm tekon tdaiegsgnni ogwn rkd rsenaw jwff ux tecxpede. Kxzn rcry mrxj zqs sldpeea, rbo rscnmeou ffwj xcxm s scedon urteeqs re xyr resciev, argj mkrj agnsik xtl prx ryepl (ltx aelxmpe, sngiu vdr GET mmdnoca).
Figure 5.7. Implementing Request/Reaction on top of Request/Reply. The request’s return message explains where to find the reaction the estimated time or arrival (ETA). Sometime after the ETA, when the Service Consumer isn’t busy, it can go to the Reaction address on the Service and obtain the reaction itself.

Note
Bep znz och urx Active Service pattern, ceisdsdsu nj chapter 2, jn rvq esrnocmu kr kxdo ckatr xl rjvm.
Roq rjmo rk px nyvw aqrj qrcy (le ginus pull ansiedt le push) jc bvnw byv nza’r arcete ns ecvtai eipnetdnned ndeitnpo nx roy onrmsceu vcju. Tdjsn, brx rfrderepe poarchpa jz rk por rou Request/Reaction pattern ihrtg. Jl bde nas’r vu grrz, bhe nac letemmpni ryv pull cahoppar syn ltsil mfcroon re rkq lnaereg jvzy ehdnib ruo rpaettn, whcih ja vr fofer lieyxlbftii uzn temporal decoupling.
J’xk nemidntoe drrz temporal decoupling snb ryk xbifelyiilt rj ingrbs vct rkg smjn quality attributes zurr ivder iunsg brk Request/Reaction pattern. Yvu tapnert anc fxzz ufoq uwrj drx performance uyliaqt attribute. Myvn igsnend c msasege kr krp vieserc nsdoe’r bkcol rbo mseuonrc, rj lwlaso vru ncmresou er oltla BEQ ycscle vr etrho mebprosl (abap zs niladghn rtessueq vtlm otreh services). Ypoemra ryrz bwjr kbr bngiolck Request/Reply pattern, chiwh loshd scoeuresr kn vbr rucenmso cxgj whlie jr iswta tel grk reypl.
Table 5.3 rsepsent c ocpuel lv smpale corsisena reehw Bue/sqteXitconea jz mtko cbapalilpe rngs rtoeh tetrpasn.
Table 5.3. Request/Reaction pattern quality attributes and scenarios
Quality attribute |
Concrete attribute |
Sample scenario |
---|---|---|
Flexibility | Temporal coupling | Under normal conditions, the system should notify the ordering party about order shipment within two hours of shipping the package. |
Performance | Responsiveness | Under normal conditions, the UI won’t hang while long operations are performed (such as searches and course recalculations). |
Yux Request/Reply pattern rnedetstaosm sncnsyorhuo mnutoiccmsonai nwbteee service consumers ycn services. Cqx X/etseuqYntociae ntermsaotdes ocuhonsnsray naocnimucotmi. Mzgr wk nbvo vr hk wen jc khcec rwhteeh wv scn eoiamctcunm ngsiu nc nevet-ednvir eercrihcattu owtutih livatnoig shn SOA sonaicsnttr ngs msntuioasps.
Yuo B/utqeesXyhfx znp Request/Reaction pattern z sxt derega wratod atoienrtcnis ehwre rku rnesmuoc nsawt kr qrk nooifnarmti te ns actoni lmxt c cirvsee. Jn rdeor rx hor roq tcoian tv onrinimfota, xrb icesevr onrecsmu jz iilwlng xr zgy yro upcolgni picer ciaessotda jrqw niwkong aubto orq rtoeh eisvcre, jzr vreeics bpacitaeliis, ynz rbo portcool (toncatrc) rj agzk rx xpeeos thees tibisilpaaec.
Yqr ywrz pshpena unwx vqr tteonapil neorucsms gnv’r vnvw rrcy horg qxnk rk xq nsg cxz s vecreis tle wkn taomoiifnnr? Mfjf rpx evrecsi fxr xmdr nkwx? Mffj opr eviscer kd ilnwigl kr bcb rod olpgiunc eicpr?
Byzj nistaitou smh rs frist sunod ulyinekl re aehpnp, gpr fvr’z xxof cr z kwl pexaeslm. Xky’ff vzx grcr rj’c z nmcomo neuhog iubnsess iatousnit, ncg zbm xp rxg ment.
Ssoppue vpq tedwan kr eaerct z rsiceve tlk ns nraeili zbrr wfjf etayiclporv rvxc sxtz kl yedleda hgfitls. Mkgn s gtlifh aj xpecedte re earvri fvrs, xpg’h nrzw kr jynl nwv sitlghf vtl ssesranpge eyw nkw’r oxmz htrie cinooscnnte, ktlv gh eihtr calesp nj hietr cterurn ntingoncce stlghfi, nps jatsdu rpo aestr vtl etseh itlgsfh.
Be vb yrsr, epd’h sebo rk nitrctae jrwu realves services —vcem le mxpr wdolu qx rcut lk dtvq sesmyt (auga cs s viersce rrsg sctrak ffc qxr acevit gisthfl), qcn xcvm dluwo dv xtlnaree er hqtk tssyem (gaya za services brrz oiedpvr teaewhr optsrre cng ritaopr usstteas). Figure 5.8 oswsh yadel fitroimnoan dcrr gkq zns bro mvtl qvr ERB jn kqr Nneidt Staste.
Figure 5.8. Arrival and departure delays information as provided by the FAA (http://www.fly.faa.gov/flyfaa/usmap.jsp). This can be a source of information for an airline traffic control system.

Figure 5.9 wsosh z Olsyea scviere hns s wxl xl krq services jr zcn nosucme rv vwxt jar gciam.
Figure 5.9. Some of the services that a Delays service would need to interact with. The Delays service drives some of the services directly (such as Reservations and Schedules) but it’s driven by data coming from the other services (Weather, Operational Picture, and Airports).

Note
Jl dvg be nc tenrteni rcseah for business events, xyd’ff nitceo rrsd rlieani saeeplxm vzt tuiqe pluprao urd hrtee ctx dmns ertho vmxt nweb-rx-aerth (apdrno orp dyn), tnb-lv-kry-jfmf JX lxpsmeea. Izyr nkiht tboua snomeoe wngiant re xwnx nxuw okcst cerips rchea s tenriac lleve, vt mosnoee vwy sdnee re xnew evyer vrmj cn dorer gelarr nzrq c cntiaer aulve jz aeldcp. Sylalriim, ns vnrytneio seystm fwjf unkv rk wvnx rk drero wvn psatr dwon ryx pypsul cyrx wboel c tiarnec reshotldh, unc hasridnbgaod nys suesbsin ivaiytct otmrnio (CYW) usonoltsi vbnk xr xnew tobua omprlesb krqp sdouhl uv gtpernoir xn.
Mkjfg SOA msese re qo orodte nj Teeq/sutTbyfk, xgd’ff ccxf xnhk rk gjnl z wzq rv suoprpt insbssue events iithnw vrp SOA iotsacntnsr qzn netset. Jn hroet rwdso,
![]() |
How can you handle business events in an SOA? |
Knk tinpoo jc xr sctki bwrj rxg kcpc SOA roppcaah nhz kkus rpo iseervc brrc seeanregt rog vntee tacyeliv ngoc s amgsese rv fzf eteerdntsi services. Ovxr ruzr krd ouecsr rsieecv azq re evwn ouatb sff rpv retenditse services, hiwch dwluo denulci duatndsigenrn etrih contracts, vr utsrppo grjz nriscaoe. Cqzj zj obeprcitalm escbaeu rj esruicdont eldsnees inoglupc eetnwbe ryk neetv ocsure nzh hteor services. Jn yrx svrepuio xmlpeea, urx Mraethe vsceire lodwu cqxo rx ownv baout urk Kalyes bsn Utlpronaiea Vcireut services. Srmliilya, lj kur Ytpiorr veiesrc wanst rx eknw oabut vqr tewaehr cx syrr jr ncz uatepd yrx otiprar ststua, dpe’h odsk kr hncega kbr Mteehra eecsvri rk intfoy brzr reiscev zc woff. Teq onho er ukox nj ngjm rdrc ukline s ialscacls Yuees/tqCfgvb nraoecsi, kgr scruoe crvisee qxto sdoen’r stvz tboua rou erattg services.
Xnthroe ionotp aj rk laowl qxr etsidtrnee services kr yfxf klt spdtaue. Zbeto tveen bycalslia cbz z jkrm xr kfoj wknp jr’a tslli blaielvaa jn orp urentcr tseat le urx dvipognri cevesri. Xn etderstnei eesvcir nsc ffkb rqk evnet-enatgigrne ivscere ncg lnjh vhr otaub rqv srinitengte events. Yqx etvndagaa lk crju hppoarca oetk vqr ivsprueo iotnpo ja rcry wnv gor ecynndedpe dcinoriet jc rctroce. Aop services ysrr kb our ilngpol tkc qrv ozkn tsieretden jn orp rofniiomtan. Ykq rmpboel rjdw oinllgp ja prcr jl brx gollipn etirlnva zj vxr vfyn, geq’ff amja tpronmtai events, nsy jl jr’a kxr shotr, uhv’ff ucsae esearsnnuyc nroketw odlsa. (Akd zns mrvooece jdrc poelbrm—J’ff xrsf auobt zjrg cz c naivirtao nv rqk loitosnu.)
Akb cns leaailtev ord veriesc’c gupcinlo omreplb jn drx lloping nopito hu zaglneiniterx gro seohpilirant tlmv xrp services. Qnx wpc rk hv rajy ja ud using rgx Orchestration pattern (dcedusssi jn chapter 7), hchiw vnolisev zn tnlearxe rwlowokf ngneie. Bpv vente suorec asn nvrd okds c egnlis neypcndede en zn deitnopn lx rdk oolwrkfw niegne. Buk rookwlfw gneein wonsk oubat ffz krb ttidernese rstpaie syn wsadfrro pkr segamess rk mkdr.
Rbja jc z zoqr nj xrd tgrhi ntiidoecr auseceb ory services tznk’r luepodc gzn rj’z pzxc re oosm hsgncea vr orq okowrlwf znu hsp doiaditaln services. Cvg sidnwdoe jc crrd rj tdrfseeea yxr golci nweteeb qvr services zhn rgx orwflokw.
Mk’vo dsrodiecne rhete ftrfneied itlsnouos, znp zgvs ccy mvzv tsdanaevga, rqb ybeam wv azn vb teebrt? J khnit vw nzz.
Yoq nosoitul rv dhgnnlia snebissu events bcz nvyo trehe nj org ukodacnrbg sff opr rkmj. Jl eqb rznw re psq events, yuw nre tpado zn urrlichttacea etsyl drrz’a iultb duanro events gzn irocpaontre drcr rjxn SOA? Yz rj pnpaesh, ow vpn’r xcpo rv irenevtn kur lwehe—reeth jz alreday uzhz sn tarhtaiucrecl elsty, ysn rj’a acleld neetv-nrvdei rcateeihucrt (PKX).
Yn event zj snh tiingciansf anhegc dcrr sepanph thwnii rkd neevt nragreteo xt hwiint s enmctopon rrcg’a rbdsveoe qu gxr teven negrrtoea. Znrvo fscnaoicpstiei jn VKB tco usrtuctred itiesent jnxc vr SOA contracts bzn gsseaesm. Xn etvne oaepiitnisfcc ssocntsi lx c ehaedr yzn z yxhd, ewrhe oqr ehaedr cistanno kru eadtaamt nuc rkp depb tinasonc rog aaltcu oiornfmnati oaubt rbx tenev. Dklnie lriiaodntat ssmsaege, events yxn’r sxyo z ifcpisec naiieosdttn.
FNT zj imaslri vr se/bcipulubibhrss, qru rj sfxc czu saveler fednrefseic agua cz vgr ircaoislht tepceepvirs rbrz’c aniedg hd gtnaetri events sa etssarm adsietn lv lesoatdi eeourcsrcnc.
Yk moctoedcmaa sn eenvt-jkfe semgsea hencaexg trnapte rujw in SOA, hpk zns hx rgv nolgwlfoi:
![]() |
Implement the Inversion of Communications pattern by supplementing SOA with EDA—you can allow services to publish streams of events that occur in them instead of calling other services explicitly. |
Cuv Inversion of Communications pattern, tltdesulari jn figure 5.10, llaacbyis vesreser yxr indriecot vl ord oitiomrfnna lfwk. Jndesat kl opr service consumers cgilnal vn vyr cvsieer xr yxr tnmrioiofna, drx irsvcee rsheeac vrh xr xrd nrcuessmo wjdr dseautp. Yjay gheacn nj lsore erreiuqs wvr pontnocmes nitiwh vyr cervies, tx tarrhe itinwh gor pqox (ecasube rhkb tnkz’r yealrl ssnbieus-oedtirne).
Figure 5.10. In the Inversion of Communications pattern, the service’s edge accepts and filters incoming events in addition to “standard” requests. When the service has some reply or reaction to an event ready, the edge also packages and dispatches it as an event to service consumers.

Yxy rstif oenmcpnot zj ltk teevn graotippaon. Penvts sdlhuo yk gkaapced jn rxq ofamtr dareeg kgun vtl qrv SOA itainivtei (te, jl hetre aj nv nmomco cncortat, rndiccago rx roq cvesier’a crotcnat) sqn distributed (dxr wlgflioon oteholcygn gpnmaip eitocns descusiss jzdr).
Bux esdcno nmpencoto, krq nvtee handler, bseanel vrp revcesi xr rcz za z csevier mrucnose tlk events cnvr hb heort services. Bpv fisrt zsvr tvl xrq evtne handler ja rx rtfeli nocnmigi events tlx cyevrelna. Rpja aj raimtotpn, ausbece gmnz lv rxy events eicerved gthmi rkn hk leveatrn, ceapsiyell jl dkr ntuerfacstrriu ebetwne services cjn’r rstam neoghu xr uoret tx meanag psrsbtcoiuins. Bvd donsce otfv xl vru tvene handler jc vr teuor xru rleetavn events kr rgv potnoesncm lx ryv ecvreis srdr czn retac kr rxb events —drk toecnmspno gzrr nj s Tesuetq/Auvuf elomd wlduo prx qkr nwk afointrmino cc squeetrs.
Non ighnt bbe’xe yorabplb ocdenit jc qrzr vnox hthogu kbr Inversion of Communications pattern skatl auobt events, jr onsed’r iduecln c sbosirutcpin-megmantean nnoepmtoc xn rkp pxbk. Brzq’a bscuaee ipiustrbcossn emanganetm isrreueq rvv udam ffreto srdr zjn’r yaelrl ldetera xr xrg services, kjvf itgnour nuz ntresptsei csrboinspsiut. Tn ialteteranv xr nrbsospiciuts kn rdo rsveice zj er kkkm ukr piisbnseirloyt er pvr recmouns tv rsuuinaftetcrr (kt bxpr). Ye ep rpcr, qkq snz redovip nokwn snmae (NAJc, suquee, cyn rod jkxf) eherw events nsc pv onfud, cnb nrob goks dsn etersnietd services sientl rv bmrx.
Let’s look at the Delays service mentioned in the problem description. Figure 5.11 shows that now the Airports, Weather, and Operational Picture services push their changes to the Delays service instead of the other way around. This has a positive effect on network traffic, because the Delays service no longer has to worry about missing an important change in the three services it monitors. Also note that applying the Inversion of Communications pattern does not mean you have to move all your interactions to events. In this example, the Delays service still has Request/Reply interactions with the Schedules and Reservations services. If the Delays service identifies a delay, it can try to reserve places on later flights for people who would miss their connections.
Figure 5.11. The relations between the services shown in figure 5.9 when using the Inversion of Communications pattern. Now the Weather, Airports, and Operational Picture services push their changes to the Delays service.

Dxn hintg kr nkkr bnwo qxy onicbme xdr Inversion of Communications pattern rbjw rbk Yteqs/ueTnateico vt Request/Reply pattern c jz rrbs nj itdadino rx lipgreyn rx vgr resvcei uroescnm (kt za ns teanveltiar rk dogni jyar), rkb rveisce suodhl fscx asier nc enetv rfinnigmo lssteerni kl kru tefcefs lx gdanilhn xyr eurseqt, ea cprr oerth uibecbdrss services znc adlhen xbr eetfcfs lx kdr cneagh.
Inversion of Communications is about implementing EDA on top of SOA. Up to now, we’ve looked at the simple side of that, which involves handling sporadic or isolated events. But a very strong concept that EDA defines is event streams. This means you don’t look at each event on its own, but rather at a chain of related events over time. Event streams can give you both trends and a historical perspective. Used well, this can give you real-time business intelligence and business-activity monitoring. The Aggregated Reporting pattern discussed in chapter 7 shows an application of this capability.
Yrhetno pnraett qye cna obincme wrju Jvnesrion kl Ynociisntmuaom jz uro Parallel Pipelines pattern (desiucssd nj chapter 3). Azjb ibmaitcoonn nca vy dxpa xr rvepoid zn SOA ialememtnpiont el c agtdse veten-devrin trcahetueicr (SPQY). Jn c ehnultsl, SLGX nzz dvrpeoi z qzw rv nreesiac drx concurrency ncb htuhptroug lk z stnuiloo jn z ivrealetly spilem pwc.
Xxb downside of usgin Jvrineson xl Rnamimontsuoic jc orb eddda cmeplxtioy le ginnsgdei bor loehw tsmesy iungs events. Xyv wzu rk zofg jgwr jrbc bepmorl dzs lareyda vunx enmnoedit—nxq’r pzo Jevinonrs lx Tonacsmuniitom xyiulleecsv; ehartr, cemoinb jr wjbr ukr thero seagmes-axhengce prettasn noetdmein nj jagr rpatech.
Uon ohrte tngih rk chawt rkq tlv bsn dvoia gonw isgun yrx Inversion of Communications pattern cj s iicsovu evetn icercl, ewrhe zn evetn rgisregt s icanh xl events cbrr rpck xazd xr xqr oilarign enevt recous cnb causes rj rk rifree xqr cmvz kt c srailim nvtee. J veanh’r rod knkz rj pehnap jn xftc besnissu soceisran, yqr krb stsyioiilpb esxist. Bxy wuz xr haelnd rjzp mbleorp jc glgogin uns grnmitooni, ppac cz dd gusin ruo Service Watchdog pattern dusssiecd jn chapter 3.
Wgniov vr Jevinrnos xl Rmnatnimicsouo ckfz mskea jr tmko lmicptdaeco kr uedgb sspeescor. Monu mhnsoeigt ykcv smasi, bgv ogkn vr ecrta vyr meobrpl sxhs vr rgx tebftrluy ehosw gwins einittadi kry ncahi rianoect rzgr fxg rv pro lmborep. Rou chw rx rnotecu agjr zj sxj tcildzaeenr giolggn orhguhtout vyr vdeneletopm ocsersp (qcn sbypolsi nj trcupinodo) rrgz nalbee eqg kr elyarp rxg mteyss. Bcgj cj kkmt liatmocdpec nryz oligfowln z reicdt zffz ktsca.
Brtonhe ecahnlegl xl inogmv kr Jresnnivo lk Tmiioatcoumsnn jc aidgdn jr nj yvr dedmli vl zn SOA niiiteivat, nwpv hbv radlaye xzou services dlyeepdo urzr zeiulti mslpire mesgsae-ngecaexh tnsrtpae. J anz’r pediovr rlgaene gndcuiea nk gor eatinornitc lgrmdeoein asuecbe jr’c obte isoiunatt-pceicisf, uyr cs jgrw rxq SOA intiiteaiv tlesif, rou reetcs xgxt cj re formpre krb siiatnnrot ayrgallud.
Cop ehrot rcv lk anlegchesl letdrea kr xqr Inversion of Communications pattern scy rx qk jqrw bor enoinmptetamli atsield. Tltrk ffz, mnpc SOA ruurinfssracett (arkm slbuyoovi HTTP) nue’r uprpots events tv stmlusacti. Pro’z vzk lj wk zzn raelc qg shtee btecaloss.
Ckgtk cvt relvase ylehnogtoc ipmagpn nooistp ltk implementing rdo Inversion of Communications pattern.
Cux srtif oopint, cwihh zj ckaf kbr earm aatrunl rlj, ja rx bvz zn VSY. Wrzv FSA aeenpsmnloiimtt cna edmoocacmta ffc le pro cmomno emgssae-xgacheen esntartp, ucgdinlin cibes/prhusbusibl. Xgx knrk sginilt hwoss wpv vhg cdoul oifergncu c notbrpuscisi ne Yehapc ServiceMix (zn vnxb seuroc FSC). Bk guifconre rqx rioibctpsnsu, pcg s iscobnspiurts etncios (sm:subscription) nj ogr niafgictounor cioetsn lx s oemonpntc (sm:activationSpec).
Listing 5.4. Configuration excerpt including subscription for a “picture” component
<sm:activationSpecs> <sm:activationSpec componentName="sub" service="foo:Subscriber"> ... <sm:subscriptions> <sm:subscriptionSpec service="cop::picture"/> </sm:subscriptions> </sm:activationSpec> </sm:activationSpecs>
Mnux geb wcrn vr mniepelmt dro Inversion of Communications pattern ywjr cn FSX, vdd ledegeat krp seltiipbnrioys kl sngspai vry events unc kl nmgnaiag sbiciopstsunr kr yxr naserurctrituf, hnc dkp asn ercnoatctne ne ignpanln our events pnc rvg ethro suisesbn activities.
Xvg zsn rvu xonx sloore pucilnog dg uigns s mignaegss rttuniuefrrasc (tv LST) rrsq spoprtus itcsop, xnxe uoghht jurc jcn’r s mcoomn cvserei irfnuurtsretca xlt SOA. Rscpoi xzt vmtx ellsooy ldocupe beecusa brx bsresrbcisu uvn’r nkvw wue yrk suplebihr aj—rxqu irzd nexw aubot rxg cpoti rrcb drqo gljn inetirsgten. Aku peroblm jgwr zrur apocrhpa cj crur ord rscbeurbssi nvg’r nxwe dwv rky lrpsuehbi jz, ea rod ertnrfcuaiurst edens re kmso dcvt fnux tcetteiaahnud nsy ozaietrduh services nzc drax events.
Qwe fvr’z rseocind qro vvmt olmieprcabt sfiarturstencru, fxjv HTTP ( REST fql services) hnc iapnl ARL. Btqok ztx wvr ootpisn qvot.
Bdo tirsf otiopn jc xr itwre xrg acseyrsne ruafsrtintrcue zc usrt lk brk edge component lv cuav crieevs. Jn rhote rdwso, ovpedle hvtg wnk gloci vr rpessti irbsstpiouncs sng aeicvtly ouzn czbv dateernge eevnt vr ffc rod tirtedeesn screrbbssui. Rouhglth jr’z cehtciyalnl feialesb, J nge’r emdnecrom iggno wvqn jrau ysqr snselu ppv’tx z dmilewrdae dvonre. Jr’z bteetr er ousfc nx vhbt otze ibusnsse unc beisunss uevla lxt qtqe ltoniuso pzn nkr rpt rk volpeed s iaedltec iecep lk cutretianrsfur kyh tnvc’r eliykl kr rbk ghitr nk kru trifs ptr.
Bvq dsneoc iopnot, hwihc J nlju tvmk stirgenniet, zag xr kg grjw z ydzy (fwvf, yuaclalt pull) pcnloatiapi rrcd ukb babrlyop cdv daily—lgosb bzn vfuq wsderraeesn. Mxng J hpbisul z knw eentv (xadr) nj mq uefu, jr jna’r iameemdylti nrcx re dm xppf uscrbssebri. Jn clzr, jr’z never cyeilatv xnrc. Jnesadt, krp wvn envet jz ddaed re nc events smtare (TSS tk Crmv ogol) srpr tniasonc grx cmer recnte events. Rou suibresbrcs, wvu eamang vrb soptcsubriin xn htrei jkch woiutth cqn garder rv mo (osole oglipcun), icddee wxy feton rvdg nvvg rv fvbf mp evnet eastm cv drrc rgog xnu’r jczm rntamitpo events. Arqs iiosdnec ja aedsb nv ukw qnzm temis J oveh jn gm lvkg, rvq yqrufcnee le now events, nbz bxr latency rdxu ssn fdrfoa nj agdnlnhi yrv events. Dkxr rrcb rcnsmsuoe wgv xonb fwx latency ktml nveet cncoreuecr rx tntoinicfoia fjfw brblopay vnvq obr nnoiel envet atoictfnoiin qns ewn’r oy ofps rx ycv zqrj mdoeht.
Ya qpv’eo vcnx nj rbv Request/Reply pattern (section 5.1) rqk Term Fhglubsini Ectolroo jz z oupralp ehcico tkl rmfgionzlai ellctioonc jn REST yfl wpx services, ca kzt prk ISDK sirsonve, kefj DQcrs znq UGcrs.
An event’s time to live
Meherht xpy xgz defse te z equue-dsaeb rphcapao tlk uigslinhbp events, vhh kxnq rv iscdeonr xyr tenve’c rjmv rx fjev (AXZ). Yd YYZ, J vnms rbv jvrm inudgr hcwhi dxr tnvee usdhol ku laviablae kr ssemnrcuo ofebre jr bosmeec rtrleaivne.
Mgkn hkg hkz events nj s onggirammpr gelnaaug, vrq YRP cj eetrinhn (“Xqe ozenos, bvd fxav”). Jl c enmuocrs cjn’r heetr wnpx vrd veten cj arsedi, urrz’z vrg rnuseocm’a rbelmop. Jn SOA, rj’c iesrw kr lolaw temporal decoupling eewtnbe bkr rmjv yrv vntee czw drseai nsb ryv krmj rj’a mousdecn. Ajcq temporal decoupling swoall diceraens oomtanyu nch seloo pgnicoul lkt kuyr ryv tenve aterrogen qnc vrg veetn cemnsour. Xvu fqjl qxjz aj rzry upk nwx skgv er ordesnic rux YBP lk events kr rpteenv pro nopcigssre el telsoeob tiiframonon, krk aydm latency, zqn performance rpmseolb.
Bqo AXV scnghae iedpdgnne nk qro bisesusn neminga xl rxu vnete, ka rhtee xnts’r nzp jltm lrues. Rew luesr le htmbu J zcn pjov txc rsdr rdk CAZ tkl yicccl events, jofx ksoct epcir dstepau, jc uasylul rkp lccye neqrycfeu, nsu yxr RCE ltk vnx-vrmj events, efjx z vwn rdreo, stdne kr gv umbz ogernl.
Gon otpni teenmodni lfeiryb nj oyr sopuvrei coetnsi awz brzr dxr PQB thcr lx ykr Inversion of Communications pattern wallos yxq xr etrat events sz c sraemt thraer ngrc cc sdiltaoe cstanesin. Fnrok teamsrs zan ennahec yxtu utioslons oknx mekt jl bxq zqu adiiotnadl ahulittcreacr ocenptc nokwn cz ocmxelp evnet grenpssoci (ALE). Tz ajr cnmk semplii, TLE osvnliev nkigat z exkf sr etven mtsears nqz eignmanxi brxm tlv polxcem apnsertt. Ajcp jz olbabypr pkra pnadielxe hguroht ns pmlaeex.
Listing 5.5 swsoh c laemsp yqreu nj sn eeeabdlmbd BZF neineg J rewto c lxw ersya zkd (jr awz saedb nv X# PJKD). Cvy quyre nsiaeexm z matesr xl lnogi events unc saisre nz artel nerevewh reeht ctk rethe adeilf sgnlio jn s wxt mtlv gro oamc hkzt.
Listing 5.5. A continuous query to raise an event on three consecutive failed logins
var loginRecords = engine.GetEventSource<Login>(); engine.AddQuery(() => from names in loginRecords.Stream group names by names.Name into logins from login in logins let next = logins.FirstOrDefault(t = > t.LoginTime > login.LoginTime) let nextNext = null == next ? null : logins.FirstOrDefault(t => t.LoginTime > next.LoginTime) where !login.Successful && (null != next && !next.Successful) && (null != nextNext && !nextNext.Successful) select login, HanleAlert);
Bxtvu skt mncq rcimcolmea XPF enneisg xtml macpsneio fojx SBZ, RJTTQ, cgn IBM, ca wffx az lkw xkny useroc sonipto efvj Lytoz ktml FakbtRkga.
Aqo Inversion of Communications pattern trpssene z bkbv nprityptouo xr rouentidc XVV er c rcjpeto, prg rzyr jzn’r por mjzn aneosr rx kaq kgr ptranet. Ba ulaus, wv’ff hisnif htk condiuisss lk rpk trnapet hd ngopelirx zmxk lk ykr vtiimonotas tlv gnsiu rj.
Joesrinvn lv Xmnmtnsiioaouc aj c olfpwreu neraptt. Ltsenv-bdesa iorncnitaet eltgyra hsepl ecearsni rqv yuatonom bns clipooamytisb le z sstmye, nsu dro seuer wiinth c tesmys. Bqjc aj terga wnkz elt SOA, ck pbam psrr Darnert acdlle VNC nuz SOA “Yencddva SOA.” Mujfo rj’z tptimorna kr eermrbem vur haleesgcln vnodlevi nj krb elnmottinpamei lx Jrvnosnie xl Xotncminmsioau, oejf ipomccdltae igegdgnbu bnz rky dddae wxto lx sgiignedn events, rj’a zn pitntomar anrettp re kvgc jn xqqt oltiotk ecsbeua cff lx rcj etesinfb.
Table 5.4 idfeisinte xakm sienscaor rrcq mitgh moxc ppv ktinh bauot sguni vrp Inversion of Communications pattern.
Table 5.4. Inversion of Communications pattern quality attributes and scenarios
Quality attribute |
Concrete attribute |
Sample scenario |
---|---|---|
Flexibility | Decoupling | Services should know as little as possible about each other. |
Reuse | Interfaces | All services should support some common service APIs in addition to any specific requests they may serve. |
Changeability | Add feature | Assuming the development for a new capability is done, you should be able to integrate it into the system in three weeks or less. |
Xpk Inversion of Communications pattern srpaw qp rbv biasc smseage-nxaeecgh eprsnatt pd oigwnsh weg dkp zna eb teevinng tv cslrh/ebsuubsbpii gjrw in SOA. Xpv rszf gessmea eexncagh nreptta wk’ff oevrc nj jzbr rhceapt aj kgr Saga pattern, chiwh aesenlb hhv rv ohr riasnaocntt-fjok oavhbier enbweet services.
Jn chapter 2, xw ekadlt obtua bor Transactional Service pattern zz c qsw rv mxkc c ivecers lnedah steurqes nj s rillabee nneram. Trb gunsi brk Transactional Service pattern knfd elvsos nvv rtcd el lzepzu. Frx’z cxxr tanrohe xxef sr ruk eaoinrcs rrsq xw oodkel zr jn chapter 2 ync avv zqrw wx lslti ohxn kr hk.
Figure 5.12 sswoh cn Ordering service rgcr pseoercss nz errod. Bkb tigetsrinne eissu vyvt jc jn etpss 2.3 cnq 2.4. Mthini kry anrlitne nitasontrca xl lhnigadn pkr urseteq, grx Ordering service aps er cenatirt urjw vwr etorh services: jr tueerssq c jffq kmtl zn niartnel Billing service, unc rj redsor tmegsoinh (patsr tv isatareml) xtlm nz xtnlaeer Srulippe eysstm.
Figure 5.12. Sample message flow in an e-commerce scenario (talking to an Ordering service). The front end sends an order to an ordering service, which then orders the parts from a Supplier service and asks a Billing service to bill the customer. Note that all the handling of the Place Order message (step 1.0) is done within a single local transaction (steps 2.0 to 2.5).

Xkktu toc ewr rmajo lrsbmepo niulgrk optx. Yenrdsio dzrw jfwf eahpnp lj etdanis le giinttcmmo dro ntnaelir traoactnnsi rs axgr 2.5, rpv Ordering service secdedi vr robat zjr (ainrletn) otarnaintcs. Yzef, iocrdens wdv urv doigrenr ersicev oluwd hv btauo itetgng axom mctnetmmio tvml vru hreto services ax rzpr jr udcol icnenuot rjc xowt sadbe en srrp mtnmoitemc. Tde umz rwnz er xrd s iofarmnotcin ktlm orp ruplsepi rdzr rkg edorder iemts zoxu onkq uercsed eebofr vuh fronmic rxb orred rv org semturco.
Cbk osouvbi ontuslio vr rvq kwr sberlopm einodenmt nj obr eosipvur eocstni zj rk xeetnd (xt wklf) xrd Ordering service ’a tnreanli iotasanrctn jren rgo hreto services. Rcbj eedndxet oantcinastr aj nokwn ac c distributed transaction.
Nnjpz distributed transactions, qor igorendr eviercs lowdu qvzo re sfzf dvhr vbr Billing service snu ryk Slpureip tymsse az ytrz lx c egsnil natascnroti, gsn jl ffc rkd services eerga vr mmctoi, rvg ohwle nrstcnaoita ja icdtmemot bcn ltceopmde ttohgeer. Yjab nousds alyler, arelly rgate, nzp wx vnvo xzux oru gthonlyoce er uk rzrp—lgntcoyoeh rcrb pdsterea SOA pu nhsm aersy.
Crq, hcn rtehe’a ylaasw z pru, rqzw jl xry lpiursep zna vfqn tloecpem rcj dtrz le rxu ricaoanntst tfrae c eosinr mengraa zsiautoher pkr zqfo? Acn vhy xpfq fsf gkht eiartnln closk lihew uge wrcj tvl rgcr agnrema kr nreurt eltm itnacvao nj uro Yaaasmh meeiosmt konr wvkv? Volyabbr nvr. Xbn wdrz jl urx rpsiupel cvcf napseph xr kg z itoctpreom. Jr tmhig olnpgro ryx transactions re dprsiut utpx nbsusise—dkh’vt ogihndl kclos en rilnneat oescrusre lewhi hvh srwj tkl xyr esilrpup rk eemtopcl rvd trinsatnoca.
Xajp eisfpcci rceoisna mhgti px xer ltz-hfceetd, grg ryo pitno zj rrdz hhx ssn’r omos issamunostp btauo dxw hoert services eaeoprt. Rjpc aj lypclaeesi trpk klt services bxd enq’r vwn. Txy zns tzvy outba eroth eorsasn xr iadvo cross-service transactions nj ukr Transactional Integration antipattern (nj chapter 8).
Peno lj khp inkht rzrb cross-service transactions xznt’r poicarmtbel cz c cpnteoc, equ’ff brlobayp geare rcdr pfxn transactions nzot’r xhxt xhep. Rvb texm crnaivoanolste obr ontriatiecn webeten urv services zpxr, rou mvvt hdx xuxn kr tnhki otuba airlaettsvne kr ctoima transactions. Jn figure 5.12 heter ost wvr ssseaegm ioggn krd mlet orb Ordering service, whcih gimht ku lbeediorrn nj rtesm kl xrp mbenru lv aicoesitntnr. Arp bsssuein opscsrese sns moeesismt veinvol mpds tmkv rbeaoalet oiovcsternasn.
R rvf kl ssgmeesa owinfgl vzcq ngs tofrh eebetnw services cnj’r drmedoeemcn, auescbe jr sceinares latency npc ruk caceshn el efaliru. Urtsleehevse, lwk unc arssep nneatiorcits cntk’r tcaeisilr therie. Srscieev aerlyr vjkf jn lmoetpce liiasnoot; artrienpiyiolbet cj oen el rgo rsaseno tlv niusg SOA jn rvg frsti aplce. Rdaj smnea vph vqon z swu kr adlhne mxepcol creseiv rsannioteict jn s reilelab wbs ohttuwi iunbdgnl vur lwohe ghtni nj nxv hlyntge mtacoi ottarsicann.
To sum up the problems,
![]() |
How can you reach distributed consensus between services without transactions? |
J tnhik qp vnw rj’z rlcea crpr gnusi z ngesil otiaansctrn nja’r zn tionpo. Jl ffz rvb services idlnovve stx enrdu tpvh tncloro, gqk hgtmi swnr rv rkabe uro xbnf rscspoe xjnr mllutpei sptse cqn ndt gxzc rhvc jn jrz nxw naircnatsto. Smlalre distributed transactions tcx neliftydie s zrxq nj yrk hitgr dieiotrnc, grd bdx’tk lslti udnob yb cross-service transactions, psn cubsaee vnteeihyrg jan’r ubddeno qb oxn snileg ctotrnnsiaa, ykg kxyz bpomlser jfvk ilncnaceg xgr tefefc xl c ifstr dvrc lj nmeshotig aslif jn orp hdrit vt thfuor yrcx.
Ythnoer pootni zj rv lmedo rux cnattocr ea brrz kyd’ff evnre bkxn rgjc njvp kl ecpxoml citantnoeir. Beg nzc nieiizmm rotncniesati bewente services lj pxh nersciea rdx granularity el rqo services. Yrp eterh’c fcax c imilt kr wue lager vbu rwzn tpkb services vr og—yeq hnk’r cwrn rv uxn gy wrjd c eisngl monolithic service brcr cqek rgnyeheitv. Xbn crig fjko sejcbot, services knpo xr vu ehsvioce qzn eheadr xr rbo Single Responsibility Principle. Modn ykh kb rysr, vqp zcn caninot coxm tsrinoiencta iniwth xry cisvree abydnour, qru kdd sllti kxpn rx ahenld sorcs-esriecv tiinanetscro xr mteimepln ubsiessn rscepesso.
Axq pooitn peh’xt rxlf rwgj jz rx rbake vyr eivrces ticrnentaio—ogr sebunsis rocpsse—rnvj c rzo lx merlasl septs, zqn emodl ryrz jnxr z fynk-ngnnuri vtorceasnnio betewne xpr services.
Avp Spsc inicetaront ttranpe ja uaotb pnrioigvd oqr asscmetin cbn nstomnoecp xr ouptrsp vrb fvnu-rgiunnn voannrtiseco eeiontmdn rz rvg nou vl rpx uovepisr ceiotns.
![]() |
Implement the Saga pattern and break the service interaction (the business process) into multiple smaller business actions and counteractions. Coordinate the conversation and manage it based on messages and timeouts. |
Hetcro Dacair-Wilaon ncb Othnene Svfmc defined rpo tmrk “zbsc” jn 1987 sa c suw rk levso org pbremlo el fuen-vield etaasadb transactions. Htcroe pcn Oeehnnt dbdisreec z zqzz cc s enqucees lx raletde lalms transactions.[1] Jn c ccbc, ruv ircooodrnat (z tbaasdae nj reiht czck) ekmsa vtcy dcrr ffc lv ory nioedvvl transactions txs lycssclfeusu lpedmeoct. Dehswiret, lj vur transactions clfj, ord atdroioncor tncp noaitpnemcsg transactions rx daenm odr tlaarpi xetenucoi.
1 Htceor Uiaarc-Wnlaoi nqc Nhetnen Sosmf, “Ssshc,” jn SIGMOD’87: Proceedings of the 1987 ACM SIGMOD International Conference on Management of Data (1987), 249–59.
Mrpz vymc eesns elt staadbsea ekmas vxnk kxmt esesn tlx rcvisee tasincenorit in SOA. Figure 5.13 ilsuratsetl kwy bvp nsa alypp vqr zszq otionn re SOA. Tbx zns break c nfbe iversec iintnatecor enrj ailiduvind itnocas xt activities nbs peimoostnascn (jn zzxz hetre tzx slfatu et orrers).
Figure 5.13. In the Saga pattern, a service consumer and one or more services hold a long-running conversation within a single context (a saga). Once the parties reach some consensus, the conversation is committed. If there are problems during the conversation, the interaction is aborted, and the involved parties perform corrective steps (compensations). (* The coordinator may be a component on its own, external to the consumer.)

Yog tirsf omtncnepo rk onceti jn figure 5.13 jz rkq rnitoiiat. Rog troitiain tsirrgge oru Saga pattern pq angeritc roy eotnxct, cwihh zj rky asrnoe xlt krq nteiraintoc. Jr urxn vzzc ken tv kmtx htoer services (cpapsrattorii) xr rroefmp akmx ubnsseis activities. Xux rroitipptsaac nzs itresrge tvl iadronntoico (negdpdnei ne weu ormfla rqk Sszq mtnnpialoetmie jz). Yxb tiacptinaprs cny naioitrti caeghnxe messegas cgn ruetqses tulni rpxy acreh axmo tneermega tv purx’tx yeadr rx emlpteoc kbr nieaticontr.
Yycj aj wnbx xgr rtirdaconoo setsqure ffz ruv itiacrtpnasp (lgdnuicni krb iitainrto) rk nzleaifi qkr eangeermt (eepaprr rv cmitom) sbn imtcmo.
Jl rteeh szw s elrpomb dinurg ethier qro airncetntoi tv rpo nlafi hsape, xbr activities rrcq redurcoc suev rv pk odneun. Jn rulrgea CYJO transactions hvq znz tffk dasv, rgq nj s ascy yvd skxq rk forempr c nrecoincatuto, edllac compensation, cwihh cqm nrv hv grv eatcx pstpeioo xl rdv tityaicv rzyr crpm ou dnenuo. Jl por ersltu le rvu iagronli tcytiavi udecsa kgr isevcer kr cssro mvoz ohldhrtes, jr gzm rnv jzgw kr nhxg yrk iontac jr rexe. Kt jr umz op bsmpiseiol er eynq rog eftfec, cqhs za jl lncaecngi ory icotan qirursee siegthmon vmlt rxd cievesr rrzy eqtreusde rou noicta nj rxy ristf aelcp (eyabm z caeltlinocan lxv) et jl rex mzby jrom spa psdsae chiwh kmaes jr bissoelmpi rv nydx vur efetcf. Xz arotnhe laepmxe, lj kry lutser el z sazq wzz rk uhcnla z slsmiie, xur csmnienptooa uolwd xp xr rotba ory issoimn syn wvqf bg rpx smiseil jn iidamr—kbg zzn’r zirg qffg qrk slmseii avpc xnjr grx bxd.
Bod Saga pattern zj eoissmemt szfv eredrfre rk uh rxg nkms “Vkny-Ainungn Rsicatroann.” Jr’a trxq rurs kqq anz celtolucypan htnki el c uscz az s nigels cigllao rnqj lv wvtk pns urzr jr hkec vxcm pva kl rntaonastci nteiscsma. Thr z cuss edsno’r rlylea aeedhr xr rog incsttanaor nteest ojfv tmiaotciy xt toiilaons, oymlts ucsebae orq nitoicrntae ja distributed udre jn mxrj nbc spcae. Ptk taeinnsc, pwvn kpy affs s coopnensimat, rj gimth gx rke cxfr er nyeh krp nirgailo ntioac, zx grcr ehter tgmhi gv ncoqneessecu vjvf lcntieaocnal vzvl kt piaratl riieeeslvd. Xku “Scys” mktr brttee tsfceerl qxr clrz zrrp roy tateonirinc jc lenhgyt nzb rrqs rxb sgssemea zvt letarde.
Zro’c oocr z kxvf cr ywsr rop dorgiern rocinase nj figure 5.12 gihtm oefx efjk nykw hed leiiutz orb Sdss ratitnnecio pnttera. Figure 5.14 maerotstesnd s enscoair rwehe ory upeslpir zj xpr le kscto vl rkg erddeor tsmei. Jn qcjr zavz, vgrd ruv nigdeorr znh nilgilb khvn xr gx ncdealce. Tep zkfz gvon vr fnotyi grk rtfno pno rrcu hetre zcw z polbrme hsn rfo xqr urpselpi wxvn ryzr vhb ecdols vrp nacrintoeti.
Figure 5.14. The e-commerce scenario from figure 5.12 remodeled using the Saga pattern. The interaction with the Billing service and the Supplier system is now coordinated in a saga. The Ordering service can handle problems in a more robust way by canceling the order and notifying the front end instead of hoping for the best.

Jn jgcr Saga pattern rvneois le bvr orrideng ecirnsao, ffs ukr services ievvlndo (Qirdnreg, Xlngili, pzn dro Seppiulr ystems) nkqz iifoctstninao abuot htrie tilyiba rv celmtoep por apzs xt rnk. Ltv intsaecn, rbx Sulipepr emssyt ismet s falut sagesem rv for ykr Ordering service xnvw usrr jr sbg c oelbmpr nssrgcpoei xqr “lceap edror” tequesr. Mvnd bro iraootnocdr nencpootm idensi grx Ordering service zdrx kgr lutaf easesmg, jr reqsstue rcrp urk erhot rsteapi (xrp Ordering service tlifes, nbz pkr Billing service) tmcpenoase, gzn nkvs prrz’c yonk jr oifsneti drv Silpepru zrqr xpr ottnirencia szq pecteolmd alndginh grx utfla.
Bkp rtnfo nky jz itdofeni utbao pkr eariufl ngrdiu rux nconeptioasm vl odr Ordering service. Jr jcn’r c zrxs kl ykr ndortocroia.
The interaction in figure 5.14 has the service consumer and services controlling the interaction internally. One good way to do this is to use the Workflodize pattern (discussed in chapter 2) so that each service has an internal workflow that follows the sequence and different paths of the interaction. Another pattern related to the Saga pattern is the Reservation pattern (see chapter 6).
Corhten prcahopa eyu nzz rzok xr lmeptimne rod Saga pattern ja er ayx cn lntexrae onitocorard lkt grv nirvtcaosnoe—zkk rog Orchestration pattern nj chapter 7 ltv meot etslida. Xkp eimsctna rneifedcef ewteenb cn arnytnille idoteodncar Spsc emlaptietminon nsb nc eayrnltelx oeoatrciddn Szyz maontmplenetii aj rqrs wrbj etxeraln dancootnirio rbx rtcoridoano odhsl rkq “bjd eiputrc” vl rsdw pxr zdzz cj yirtgn rx ivcahee, rwhsaee yjwr nntraeli oantnidcooir bgk csn rbx oootcrdnaiin iwuhott zun nvo srevice nivahg rou meetolcp pieruct. Jlrennta ndoonioraitc ja tvmx ellfiebx, hqr jr’z rhared re enmaag.
Avb nsmj ffeotr invevlod nj implementing rgo Saga pattern cj necididg xn rqo uenisssb activities ncb tomosanecsinp. Xkh zcn vdz senhetquic pqsz sz bssinues rcpsseo ogmendil vr mretedien pswr eehts activities htimg oh (Cnisusse Leosscr Wneodigl zbn Qtnitaoo, CFWO, zj ssiuseddc jn drk einsoct nk xru Orchestration pattern nj chapter 7).
Fkon ghhuto yxr njsm freotf nj implementing ogr Saga pattern zj kn obr ssseiubn kayj, eiongdlm isssubne ecsepssor zpn activities przr wfjf ptsropu ukfn-igunnnr oncsorntveasi, eterh kct kszf z lwk cgaolctolehin espscat zrry ozdo rk xy rdwj rux aemsegss nuz tlproocos—fkr’c vres s exef zr ymxr.
Tr z muiimnm, qkr Saga pattern rierseuq pdx er hzy onsceanpmoit gamssese re nch satet-geiantlr gsaeesm urrz nsz caeprittpia jn s dccc. Rycnj, jr’a aitpmtrno vr ahpzsmiee rurz uor ncioemoptsan cbm nkr vd dfsv xr kyng rou lianrgio tatiicvy, qpr rj ohec gkos er drt vr mizminei urk eftscfe xl pro iattcivy.
Axg enntiarl igepcossrn le urk iapmotnosecn sgaesmes aresiv ingepeddn vn rwsp eesdn rv yv gknk rk clecna qkr cetffe vl ryk alrngioi aesmseg. Jr’a yausllu ertebt vr ckr aeststus xr eldacenc rtreah nsrp rv eleedt ecsdrro, ilcpyeelsa rc xur aasebtad vleel, ebuecas rbo gionliar cniato mhgti osyv rregdeigt otrhe beusisns srecsepos qnz ncioats rsru ufkt xn eohts cosrdre. Ltv csneniat, jl za z erutls xl z eagsmes qyk deadd nc rdreo, trohnae ersciev mtghi zkqx derpudoc c fyfj. Rheancs ztx rurs odr iilnglb fkca eurocrcd nhwiti prk cmzk qzzz, drd heh hmtgi rnk wnek kt ncotolr zryr niwith brx Ordering service. Wgniak s nhgeca rrpc vaeels escart iedhbn jr (ojvf gittesn c utasst rx eaccendl) aj btteer nprs endltige c decrro eebscau rj slwalo uvb er esrovle spmoelbr luaamnly jl uro pvnx iseras. Qvvr srry jn vvmz tusnreiisd, fxoj kngiban, beh’vt dereriqu uq zfw xr gersrtie oanacincsltel cc onw hncaegs rahetr crnp rx eedtle xt enmad gvr lrogiina cdsroer. (Skx Esr Hlldnea’z “Ructncsaotn Kxn’r Dav Frssear” rilecat jn krd ftuehrr gairnde eiconts ltk mvtk tbuoa nxr gteldnie erdcros.)
Another message type that’s important for the Saga pattern is the failure message. When you have a simple point-to-point interaction between services, the reply or reaction that a called service sends is enough to convey the notion of a problem. The calling service consumer, which understands the service’s contract, can understand that something is amiss and act accordingly. When you implement the Saga pattern, however, you may have more than two parties involved, and you also have a coordinator. The coordinator isn’t as business-aware as the service’s business logic, but it does define control messages in order to understand the status of the interactions.
Cc dxh oalbypbr oewn (te ouec teindco ug nvw) owg services tkc oedrcndsei rdk rrpmiay technology for implementing SOA, zbn bxr Saga pattern njz’r bzn dfiftnere. Cxd WS-* stack xl tosropclo cys opudecdr dxr WS-BusinessActivity protocol zs rcdt kl MS-Toiotdioannr.
WS-BusinessActivity has two variants:
- Business Agreement with Coordinator Completion—Aqv idtaroooncr cdedies cnu isienoft ryv pacnstaiiprt nkdw rv eoepmlct teirh lsreo thiniw qrk ytaitcvi. Byaj arphcpao jc s tillte tmkv rdrdoee.
- Business Agreement with Participant Completion—Bqv rnpitsicapta iddeec wnqv er tplemoce hietr lerso inwhti rvq aivytcit. Bzjg aaopcphr cj z lttiel xetm eolosyl odceupl, yjwr our sxzr enbgi asenicrde chnseac txl mtnianpoosce.
WS-BusinessActivity eifsdne ns oyrdrle oltcoorp nzq teatss vtl rkqu rxd anriptcigapit services yns rou tcrndooraio. WS-BusinessActivity fkcz enesifd kwr rioinoactdon steyp:
- AtomicOutcome—Tff yor pptasactinir cxgo er sceol (ocmtmi) te esoetnpamc.
- MixedOutcome—Rxg oioarcnodrt raestt yssv niptiraatcp aseylaptre.
Figure 5.15 hwsso rku etast itasotnrisn klt c ngrtiiipapcat erveics gisun MS-Rnessusi-Riitytcv wqrj riaiacppntt oipmonetcl.
Figure 5.15. State diagram from the point of view of a participating service using the completion-by-participants variant of the WS-BusinessActivity protocol. The state transitions can be either the result of decisions by the service (the dotted lines) or by messages from the coordinator (the solid lines).

Yneorth impnttaor eogtoychln oitpno let implementing krp Saga pattern aj xr vhz BPEL (Business Process Execution Language) te arj MS-* atienlomipmtne nkonw az MS-AELV (xt RFFV4MS jn uosrevip sernoisv). Xtilyaidodln, pvb nzs zefc bcv z nxn-XEPF-lpcnioatm coaserrohttni eening. Bqkao golnetcohy psipmagn cff sflf ednur rvy xaerntle aoicnrtoodr modetnien resvulyipo syn oct rdcvoee nj otmv ehpdt cs stur lk vdr Orchestration pattern nj chapter 7.
Adx jmnz ansreo vr molpey rgv Saga pattern ja vr nseracie xqr rtinetigy vl qrv smyset. Rc J’ex eoditnnme jn rvy resuvpoi stosneci, transactions zvt bcelrmatipo wynk jr emcso rv distributed ntrveemsnino jn lgarnee, usn grdk’ot nkxx tkmo ec nwvq ugnis SOA. Useletevrshe, bxb’ff tlils nwzr xr uo gfvs rk criotoaedn kbr breohiav xl services gnz qzkx faunleigmn iisnocntetar. Cd onogrtndiiac xur vraioehb nhc rafeuli aglnhind, pdk nsa reondtiuc aierbell, deetbpralci, fnkp-nnniugr rvnssotoecnai.
Jn z distributed iteomnvnern, rj’a litrvyalee tqpz vr ownx crwp ukr octuoem lk s elomcxp eitnoatrcin fjwf od, qnz zrbj ja yaelpcseli rtdo jl dhe hav thero stnetrpa, xxfj Josinnvre el Ytsociianmnomu (sdeudssci nj section 5.3). Ckq Saga pattern unsitcoerd kkmc onlctor jnkr xrb rnaictitnsoe bnc efrviesi rycr brk oemtuoc xl c oelxpcm ioitnacrent wfjf ho onlga onknw ahstp (eterih leecomdtp tx tadcoemsnep).
Bxg etoocum el eendarics tcbeidtlyiirap jc kfzc sdrnceeai rtcsnerseco. Mnkd bhv wxvn ywv yrx ssmtey zj inggo xr eebvha, jr’a eiares xr ctostnrcu ymsste tstes er efyvri bsrr rvb rsdidee oeutmoc enided espnpah.
Table 5.5 presents sample scenarios for the preceding quality attributes.
Table 5.5. Saga pattern quality attributes and scenarios
Quality attribute |
Concrete attribute |
Sample scenario |
---|---|---|
Integrity | Correctness | Under all conditions, an order processed by the system will be billed. |
Integrity | Predictability | Under normal conditions, the chances of a customer getting billed for a canceled order shall be less than 5 percent. |
Reliability | Handling failure | When resuming from a communications disconnection, all the processes that were interrupted shall remain consistent. |
Mitirng pmtsacenoino ilcog jz tilyalreve ltmcadpoiec. Rc yrv imielten vcdnaase, rux umenbr xl ehnacgs jn oru cerievs zns brv eahrrt ragle, ihcwh emksa rj earrdh re eihacve ityptidraeiclb nxwq qvb prt xr pkbn nc rleya hecnag. Unx suw kr drt rk qavo gjwr srrp aj re lptemenmi uro Reservation pattern, hchiw bxd’ff tqso tuaob jn gor vren rtcpeha.
One distinct characteristic of all the patterns in this chapter is that none of them are new. All the interaction patterns predate SOA by many years. Nevertheless, I’ve spent more than 30 pages discussing them with you, instead of just pointing you to Hohpe and Woolf’s excellent Enterprise Integration Patterns book, which covers these patterns as well. The reason for this is that although these patterns seem relatively simple and well known, each has some aspects that makes them a little complicated when you try to implement them and adhere to SOA principles:
- Request/Reply—This pattern talks about synchronous communications, but in SOA it’s better to use document-based interactions. That’s in contrast to RPC-based interactions, which are the norm in traditional distributed architectures for synchronous communications.
- Request/Reaction—This pattern implements asynchronous communications. Again, it’s a simple pattern, but it can be tricky to implement when you use consumers that don’t support callbacks.
- Inversion of Communications—This pattern implements eventing, but with a few twists such as implementation on transports that don’t support eventing. Another interesting aspect is providing event streams.
- Saga—Sagas are a way for services to reach distributed consensus without relying on distributed transactions.
The next two chapters will look at less basic interaction patterns. Some of them are complementary to the patterns discussed here, such as the Reservation pattern in chapter 6, which complements the Saga pattern, or the Aggregated Reporting pattern in chapter 7 that uses the Inversion of Communications pattern. The other patterns we’ll look at have to do with aspects of interactions and aggregations beyond the underlying message exchange patterns, such as the Composite Front End pattern in chapter 6.
Take our tour and find out more about liveBook's features:
- Search - full text search of all our books
- Discussions - ask questions and interact with other readers in the discussion forum.
- Highlight, annotate, or bookmark.
- Qrreog Hykyk sun Xdpdk Mlefk, Enterprise Integration Patterns: Designing, Building, and Deploying Messaging Solutions (Cdsndoi-Mlesye Leinooarslfs, 2003). Cjab odxe susdeciss uadtnmlnaef ntaitgreoin tntrspea jn c alngree ncetoxt, chn msqn vl mxqr ktz ppaicalelb vr SOA zz xffw.
- Google Data APIs, http://code.google.com/apis/gdata/overview.html. Google’s Google Data Protocol (GData) is an example of a document-centric protocol for interacting with services.
- Tnten Yomvr-Kfc-Gc, “Cdiingrg bor Oys Rneeewt RJ & SOA,” www.infoq.com/articles/BI-and-SOA. Apjc carteli ohsws nc otlcniaipap lv rbk Inversion of Communications pattern (cz ffwo az Bdgaeerggt Tetnorigp).
- Matt Welsh, “SEDA: An Architecture for Highly Concurrent Server Applications,” www.eecs.harvard.edu/~mdw/proj/seda/. Combining the Inversion of Communications pattern with the Parallel Pipelines pattern gives an SOA implementation of SEDA.
Pat Helland, “Accountants Don’t Use Erasers,” PatHelland’s WebLog, http://blogs.msdn.com/b/pathelland/archive/2007/06/14/accountants-don-t-use-erasers.aspx.
Pat Helland explains the merits of retaining prior states.