mule 异步方式是一种单向调用,调用者不需要获得响应。

来源:互联网 发布:卡尔曼滤波算法视频 编辑:程序博客网 时间:2024/05/17 23:52

异步方式通过inboundoutbound endpointexchange-pattern=”one-way”实现。

使用基本的Stdio Transport验证,通过标准输入传输字符串,将其原样传递给标准输出进行显示。相应配置如下:

stdio-asynchronous-single.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.          xsi:schemaLocation="  

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

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

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

10.    

11.      <stdio:connector name="stdioConnector"  

12.              messageDelayTime="1234"  

13.              outputMessage="abc"  

14.              promptMessage="bcd"  

15.              promptMessageCode="456"  

16.             />  

17.    

18.    

19.      <model name="model">  

20.              <service name="echo">  

21.                  <inbound>  

22.                      <stdio:inbound-endpoint system="IN" exchange-pattern="one-way" />  

23.                  </inbound>  

24.                    

25.                  <component>  

26.                      <singleton-object class="com.easyway.esb.mule.stdio.StdIo" />  

27.                  </component>  

28.                  <outbound>  

29.                      <pass-through-router>  

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

31.                      </pass-through-router>  

32.                  </outbound>  

33.              </service>  

34.      </model>  

35.  </mule>  

 测试代码:

 

 

 

Java代码  

1.      String configFile = "stdio-asynchronous-single.xml";  

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

3.         MuleContextFactory muleContextFactory = new DefaultMuleContextFactory();  

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

5.                 configFileArr));  

6.         muleContext.start();  

异步方式适用于简单的消息传递的场景。

0 0
原创粉丝点击