5.4 異步請求-響應方式異步
異步請求-響應方式即請求方調用服務後不須要當即得到返回結果,component將請求發送給其餘外圍系統處理(可能有多個),所有處理完畢後經過指定的異步應答Router返回給請求方。async
圖 Asynchronous Request-Responsespa
異步請求-響應方式經過在OutBound Endpoint中增長reply-to以及增長async-reply節點實現,響應配置以下:code
<flow name="echo"> <inbound-endpoint address="http://localhost:7007/services/Echo" exchange-pattern="request-response" /> <cxf:jaxws-service serviceClass="demo.mule.umo.Echo" /> <component> <singleton-object class="demo.mule.umo.StdIo" /> </component> <vm:outbound-endpoint path="vm" exchange-pattern="request-response" /> </flow> <flow name="vm"> <vm:inbound-endpoint path="vm" exchange-pattern="request-response" /> <component> <singleton-object class="demo.mule.umo.Vm" /> </component> <stdio:outbound-endpoint system="OUT" exchange-pattern="one-way" /> </flow>
異步請求-響應方式適用於請求須要被多個遠程服務並行處理,結果須要彙總處理後返回的場景。component
注:上述代碼未運行經過,queue1和queue2得到了請求消息並正常處理,但返回至async-reply時拋出異常,暫未定位到問題。router
後將collection-async-reply-router改成single-async-reply-router未報異常,代碼示例以下:io
<service name="async req-rep"> <inbound> <stdio:inbound-endpoint ref="stdioInEndpoint" /> </inbound> <component class="demo.mule.umo.Echo" /> <outbound> <multicasting-router> <vm:outbound-endpoint path="async.queue1" exchange-pattern="one-way" /> <vm:outbound-endpoint path="async.queue2" exchange-pattern="one-way" /> <reply-to address="vm://reply" /> </multicasting-router> </outbound> <async-reply timeout="5000" failOnTimeout="true"> <vm:inbound-endpoint path="reply" exchange-pattern="one-way" /> <single-async-reply-router /> </async-reply> </service>
等有空看看collection-async-reply-router吧,或者自定義router。ast
to be continued...class