Mule ESB 學習筆記(6)

5.4 異步請求-響應方式

異步請求-響應方式即請求方調用服務後不需要立即獲得返回結果,component將請求發送給其他外圍系統處理(可能有多個),全部處理完畢後通過指定的異步應答Router返回給請求方。

圖 Asynchronous Request-Response

異步請求-響應方式通過在OutBound Endpoint中增加reply-to以及增加async-reply節點實現,響應配置如下:

<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>

異步請求-響應方式適用於請求需要被多個遠程服務並行處理,結果需要彙總處理後返回的場景。

注:上述代碼未運行通過,queue1和queue2獲得了請求消息並正常處理,但返回至async-reply時拋出異常,暫未定位到問題。

後將collection-async-reply-router改爲single-async-reply-router未報異常,代碼示例如下:

<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。

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章