扫一扫
分享文章到微信

扫一扫
关注官方公众号
至顶头条
Mule的消息路由5
注意:在Mule的以往版本中,远程服务需要设置remoteSync属性的值为true用于配置同步处理。从Mule 2.2开始,remoteSync属性已经被删除,只需要设置synchronous属性的值为true就可以创建同步流。
异步Request-Response
在大多数复杂的场景中,可以使用request-response消息,并使用后端(back-end)流程调用其它的服务,并基于多个服务调用的结果异步地返回一个回复。你可以将入站端点的synchronous属性设置为false,因为异步回复路由器会处理该回复,除非你想给调用者发送响应。这就是异步request-response消息类型。
在下面的例子中,HTTP端点接收一个请求,并使用Multicast路由器将该请求广播到两个端点,再将这些结果以异步的方式发送到一个JMS端点。
<model name="Async_Request-Response_Message_Pattern"> 
 <service name="AsyncRequestResponseService"> 
  <inbound> 
   <!-- 
    将synchronous设置为“false”,因为response将由异步回复路由器处理 --> 
 
   <http:inbound-endpoint host="localhost" port="8080" 
        path="/mule/services" synchronoussynchronous="false"/> 
  </inbound> 
 
  <component class="org.myorg.WidgetHandler"/> 
 
  <!-- 配置异步回复的设置。这个例子使用了收集异步回复路由器,
   在发送回复信息之前,它将所有的响应信息收集在一起。 --> 
 
  <async-reply timeout="5000> 
   <collection-async-reply-router/> 
   <jms:inbound-endpoint queue="reply.queue"/> 
  </async-reply> 
 
  <!--设置负责接收和处理消息的端点以及回复消息的端点  --> 
 
  <outbound> 
   <multicasting-router> 
    <reply-to address="jms://reply.queue"/> 
    <jms:outbound-endpoint queue="service1" synchronous="false"/> 
    <jms:outbound-endpoint queue="service2" synchronous="false"/> 
   </multicasting-router> 
  </outbound> 
 </service> 
</model>
如果您非常迫切的想了解IT领域最新产品与技术信息,那么订阅至顶网技术邮件将是您的最佳途径之一。