Mule ESB 学习笔记 异步请求-响应方式

本文深入探讨了Mule CFX中异步请求-响应方式的应用,通过XML配置文件展示如何实现请求发送、多路径处理及异步应答过程,同时提供了启动和测试代码实例,帮助开发者掌握这一高效处理并发请求的技术。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >


5.4 异步请求-响应方式

异步请求-响应方式即请求方调用服务后不需要立即获得返回结果,component将请求发送给其他外围系统处理(可能有多个),全部处理完毕后通过指定的异步应答Router返回给请求方。


异步请求-响应方式通过在OutBound Endpoint中增加reply-to以及增加async-reply节点实现,响应配置如下:

cxf-synchronous-request-response.xml

Xml代码  

.      <?xml version="1.0" encoding="UTF-8"?>  

      <mule xmlns="http://www.mulesoft.org/schema/mule/core"  

            xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"  

           xmlns:spring="http://www.springframework.org/schema/beans"  

           xmlns:stdio="http://www.mulesoft.org/schema/mule/stdio"  

           xmlns:vm="http://www.mulesoft.org/schema/mule/vm"  

            xmlns:http="http://www.mulesoft.org/schema/mule/http"  

           xmlns:https="http://www.mulesoft.org/schema/mule/https"  

          xmlns:mulexml="http://www.mulesoft.org/schema/mule/xml"  

       xmlns:axis="http://www.mulesoft.org/schema/mule/axis"  

        xmlns:cxf="http://www.mulesoft.org/schema/mule/cxf"  

        xsi:schemaLocation="  

                    http://www.mulesoft.org/schema/mule/stdio http://www.mulesoft.org/schema/mule/stdio/current/mule-stdio.xsd  

           http://www.mulesoft.org/schema/mule/core http://www.mulesoft.org/schema/mule/core/current/mule.xsd  

            http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-current.xsd  

           http://www.mulesoft.org/schema/mule/http http://www.mulesoft.org/schema/mule/http/current/mule-http.xsd  

            http://www.mulesoft.org/schema/mule/vm http://www.mulesoft.org/schema/mule/vm/current/mule-vm.xsd  

             http://www.mulesoft.org/schema/mule/cxf http://www.mulesoft.org/schema/mule/cxf/current/mule-cxf.xsd">  

  <vm:connector name="vm"  

          numberOfConcurrentTransactedReceivers="1" />  

           

           

     <stdio:connector name="stdioConnector"  

           messageDelayTime="1234" outputMessage="输出信息" promptMessage="输入信息:" />  

      <model>  

          <service name="async req-rep">    

            <inbound>    

                  <stdio:inbound-endpoint name="in" system="IN"     connector-ref="stdioConnector" exchange-pattern="one-way" />  

             </inbound>    

             <component class="com.easyway.esb.mule.cxf.StdIo" />    

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

      </model>  

  </mule>  

 

服务器启动并测试:

 

 

 

Java代码  

public class MuleCxfMain {  

           

         public static void main(String[] args) {  

             try {  

                 String configFile = "cxf-synchronous-request-response.xml";  

                  String[] configFileArr = new String[] {configFile };  

                MuleContextFactory muleContextFactory = new DefaultMuleContextFactory();  

                 MuleContext muleContext = muleContextFactory.createMuleContext(new SpringXmlConfigurationBuilder(  

                        configFileArr));  

            muleContext.start();  

        } catch (Exception e) {  

             e.printStackTrace();  

          }  

    }  

 }  

 

   

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值