5.4 异步请求-响应方式
异步请求-响应方式即请求方调用服务后不需要立即获得返回结果,component将请求发送给其他外围系统处理(可能有多个),全部处理完毕后通过指定的异步应答Router返回给请求方。
图 Asynchronous Request-Response
异步请求-响应方式通过在OutBound Endpoint中增加reply-to以及增加async-reply节点实现,响应配置如下:
cxf-synchronous-request-response.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>
服务器启动并测试:
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(); } } }
异步请求-响应方式适用于请求需要被多个远程服务并行处理,结果需要汇总处理后返回的场景。
相关推荐
文档主要介绍了Mule ESB的使用方法,并结合具体实例加深对ESB的理解,对新手很有帮助哦!
Mule ESB 是一个轻量级的基于java的企业服务总线和集成平台, 使得开发人员可以快速,简单的连接多个应用, 使得它们可以交换数据。 Mule ESB 容易集成现有异构系统,包括:JMS, Web Services, JDBC, HTTP, 等. ESB...
Mule ESB 项目在Linux中的部署与开发与应用案例
MuleESB是一个基于Java的轻量级企业服务总线和集成平台,允许开发人员快速便利地连接多个应用,并支持应用间的数据交换。MuleESB支持集成现有系统而无论其底层采用何种技术,如JMS、WebServices、JDBC、HTTP以及其他...
Mule ESB应用部署 Mule ESB应用的目录结构,配置文件说明
ESB原理及Mule ESB实践
收集了一些esb的资料,包括mule,servicemix等开源esb的使用等。
mule,mule esb,Mule,ESB
mule -esb 源码
MuleESB3.0 属于轻量级的消息框架和整合平台,mule云
mule esb开发手册
mule esb 项目 例子 入门
MuleESB集成webservice+restful(sprintboot+mybatis+mysql)+activeMQ+javamail,五天的研究成果,集成了我所关注的点,希望有更多的朋友一起学习进步。
mule esb 的 简单介绍, 以及一些主要特性的介绍
mule esb mule esb 开发工具
MuleEsb开源框架简介.pdf
mule esb mule esb打包手册文档
mule的最新版本mule-standalone-3.1.1