【问题标题】:How to Implement Parallel Processing of Message in Mule using VM and Request-Reply Scope如何使用 VM 和 Request-Reply Scope 在 Mule 中实现消息的并行处理
【发布时间】:2014-12-05 22:30:08
【问题描述】:

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

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

Request-Reply Scope:

我想使用 Request-Reply Scope 来使用 VM 实现与 Mule 的异步并行处理。 为此,我使用了这个链接,但我仍然需要更多地了解它是如何工作的。

Blog:

【问题讨论】:

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


    【解决方案1】:

    在这里,我尝试并通过代码得到了我的问题的答案,请看一下,我正在打印线程 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>

    【讨论】:

      【解决方案2】:

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

      我们可以将其概括为异步端点的同步模拟器。在您给出的示例中,您可能可以利用 mule 对标头的回复来简化相同的操作。

      【讨论】:

      • 所以这意味着当我发送消息时假设它被分配给线程 1。现在线程 1 仍然被阻塞,直到它在回复范围内获得响应..
      猜你喜欢
      • 2014-04-03
      • 2017-06-26
      • 2014-09-11
      • 2012-10-04
      • 2013-08-08
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-11-01
      相关资源
      最近更新 更多