mule3

MuleESBEIPSOA同步方式

5.3 同步方式

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

图 Synchronous

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

cxf-synchronous-request.xml

 

Java代码  

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

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

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

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

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

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

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

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

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

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

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

12.        xsi:schemaLocation="  

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

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

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

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

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

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

19.    <vm:connector name="vm"  

20.          numberOfConcurrentTransactedReceivers="1" />  

21.            

22.            

23.      <stdio:connector name="stdioInEndpoint"  

24.           messageDelayTime="1234"  

25.              outputMessage="abc"/>  

26.    

27.                

28.      <flow name="echo-flow">    

29.          <inbound-endpoint address="http://localhost:7007/services/Echo"    

30.              exchange-pattern="request-response" />    

31.          <cxf:jaxws-service serviceClass="com.easyway.esb.mule.cxf.Echo" />    

32.          <vm:outbound-endpoint path="vm" exchange-pattern="request-response" />    

33.      </flow>    

34.        

35.        

36.      <flow name="vm-flow">    

37.          <vm:inbound-endpoint path="vm" exchange-pattern="request-response" />    

38.          <component>    

39.              <singleton-object class="com.easyway.esb.mule.cxf.VM" />    

40.          </component>    

41.          <stdio:outbound-endpoint system="OUT" exchange-pattern="one-way" />    

42.      </flow>  

43.    

44.    

45.  </mule>  

 

 

 

 

 

Java代码  

1.      import org.mule.api.MuleEventContext;  

2.        

3.      /** 

4.       * <p>功能描述,该部分必须以中文句号结尾。<p> 

5.       * 

6.       * 创建日期 2013-8-22<br> 

7.       * @author  zhanghuan

8.       * @version $Revision$ $Date$ 

9.       * @since   3.0.0 

10.   */  

11.  public class VM  implements  org.mule.api.lifecycle.Callable {  

12.      /* 

13.       *@see org.mule.api.lifecycle.Callable#onCall(org.mule.api.MuleEventContext) 

14.       */  

15.      @Override  

16.      public Object onCall(MuleEventContext arg0) throws Exception {  

17.          System.out.println("VM.....dispose");  

18.          return "vm ,hello";  

19.      }  

20.  }  

 

测试:

Java代码  

1.      public class MuleCxfMain {  

2.            

3.          public static void main(String[] args) {  

4.              try {  

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

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

7.                  MuleContextFactory muleContextFactory = new DefaultMuleContextFactory();  

8.                  MuleContext muleContext = muleContextFactory.createMuleContext(new SpringXmlConfigurationBuilder(  

9.                          configFileArr));  

10.              muleContext.start();  

11.          } catch (Exception e) {  

12.              e.printStackTrace();  

13.          }  

14.      }  

15.  }  

 

 

同步方式适用于通过Mule调用远程服务的场景。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值