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。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值