欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

Mule ESB 学习笔记(4)同步方式

程序员文章站 2022-07-12 18:57:32
...

5.3 同步方式

         同步方式即请求方调用服务后,component将处理结果发送给另一个外部服务处理,并将处理结果反方向返回。

Mule ESB 学习笔记(4)同步方式
            
    
    博客分类: 企业应用面临的问题企业中间件开源组件的应用 MuleESBEIPSOA同步方式 

图 Synchronous

同步方式通过inboundoutbound endpointexchange-pattern=”request-response”实现,相应配置如下:

cxf-synchronous-request.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="stdioInEndpoint"
         messageDelayTime="1234"
            outputMessage="abc"/>

            
	<flow name="echo-flow">  
	    <inbound-endpoint address="http://localhost:7007/services/Echo"  
	        exchange-pattern="request-response" />  
	    <cxf:jaxws-service serviceClass="com.easyway.esb.mule.cxf.Echo" />  
	    <vm:outbound-endpoint path="vm" exchange-pattern="request-response" />  
	</flow>  
	
	
	<flow name="vm-flow">  
	    <vm:inbound-endpoint path="vm" exchange-pattern="request-response" />  
	    <component>  
	        <singleton-object class="com.easyway.esb.mule.cxf.VM" />  
	    </component>  
	    <stdio:outbound-endpoint system="OUT" exchange-pattern="one-way" />  
	</flow>


</mule>

 

 

 

 

 

import org.mule.api.MuleEventContext;

/**
 * <p>功能描述,该部分必须以中文句号结尾。<p>
 *
 * 创建日期 2013-8-22<br>
 * @author  $Author$<br>
 * @version $Revision$ $Date$
 * @since   3.0.0
 */
public class VM  implements  org.mule.api.lifecycle.Callable {
    /*
     *@see org.mule.api.lifecycle.Callable#onCall(org.mule.api.MuleEventContext)
     */
    @Override
    public Object onCall(MuleEventContext arg0) throws Exception {
        System.out.println("VM.....dispose");
        return "vm ,hello";
    }
}

 

测试:

public class MuleCxfMain {
    
    public static void main(String[] args) {
        try {
            String configFile = "cxf-synchronous-request.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调用远程服务的场景。