如何使用VM和请求 - 回复范围实现Mule中消息的并行处理

时间:2014-12-04 14:37:24

标签: mule mule-studio mule-el mule-component mule-cluster

您好我正在使用Mule Any Point Studio,我很想知道它如何与VM和Request-Reply范围一起工作,以便Mule能够异步处理多个来自Mule的来电。

我只是想知道Request-Reply范围内部是如何工作的。我在给定的链接中提到了完整的Mule教程。但我没有得到正确的工作理念,我是新的蜜蜂。

Request-Reply Scope:

我想使用Request-Reply Scope来使用VM实现与Mule的异步并行处理。 为此我通过这个链接,但我还需要更多关于它的工作原理。

Blog:

enter image description here

2 个答案:

答案 0 :(得分:2)

在这里,我试着用代码得到了我的问题的答案请看看这个,我正在打印线程ID,它将清楚地说明它的工作原理。

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

<mule xmlns:json="http://www.mulesoft.org/schema/mule/json" xmlns:ws="http://www.mulesoft.org/schema/mule/ws" xmlns:vm="http://www.mulesoft.org/schema/mule/vm" xmlns:http="http://www.mulesoft.org/schema/mule/http" xmlns:tracking="http://www.mulesoft.org/schema/mule/ee/tracking"
xmlns="http://www.mulesoft.org/schema/mule/core" xmlns:doc="http://www.mulesoft.org/schema/mule/documentation" xmlns:spring="http://www.springframework.org/schema/beans" version="EE-3.5.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-current.xsd
http://www.mulesoft.org/schema/mule/core http://www.mulesoft.org/schema/mule/core/current/mule.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/ee/tracking http://www.mulesoft.org/schema/mule/ee/tracking/current/mule-tracking-ee.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/ws http://www.mulesoft.org/schema/mule/ws/current/mule-ws.xsd
http://www.mulesoft.org/schema/mule/json http://www.mulesoft.org/schema/mule/json/current/mule-json.xsd">
  <flow name="mule-request-replyFlow1" doc:name="mule-request-replyFlow1">
    <http:inbound-endpoint exchange-pattern="request-response" host="localhost" port="8081" path="rr" doc:name="HTTP" />
    <request-reply doc:name="Request-Reply">
      <vm:outbound-endpoint exchange-pattern="one-way" path="req" doc:name="VM" />
      <vm:inbound-endpoint exchange-pattern="one-way" path="res" doc:name="VM" />
    </request-reply>
    <logger message=" Message payload after Outbound  #[message.payload] and Thread is #[Thread.currentThread().getName()] and Thread ID is #[Thread.currentThread().getId()]" level="INFO" doc:name="Logger" />
    <object-to-string-transformer doc:name="Object to String" />
  </flow>
  <flow name="mule-request-replyFlow3" doc:name="mule-request-replyFlow3">

    <vm:inbound-endpoint exchange-pattern="one-way" path="req" doc:name="VM" />
    <http:outbound-endpoint exchange-pattern="request-response" method="GET" address="http://localhost/service/orderservice" doc:name="HTTP" />
    <object-to-string-transformer doc:name="Object to String" />
    <logger message="Response Handler Payload is #[message.payload] and Thread ID is #[Thread.currentThread().getId()]" level="INFO" doc:name="Logger" />
    <vm:outbound-endpoint exchange-pattern="one-way" path="res" doc:name="VM" />
  </flow>
</mule>

答案 1 :(得分:1)

request-reply只是将收到的消息发送到请求端点,然后阻止当前线程,直到消息到达回复端点,其相关ID与发送到请求端点的相关ID相匹配

我们可以将它概括为异步端点的同步仿真器。在你给出的例子中,你可以简化利用mule回复标题的方法。