How to Implement Parallel Processing of Message in Mule using VM and Request-Reply Scope

1.2k Views Asked by At

Hi i am working with Mule Any Point Studio and i am curious to know about how this works with VM and Request-Reply scope so that Mule is able to asynchronously process the multiple incoming calls to Mule.

I just want to know how Request-Reply scope works internally. I have gone through complete Mule Tutorial as mention in the given link. But i didn't get the correct idea of working , i am new bee to this.

Request-Reply Scope:

I want to use Request-Reply Scope to implement the Async Parallel Processing with Mule using VM. For this i went through with this Link but still i need more light on how this works.

Blog:

enter image description here

2

There are 2 best solutions below

1
On BEST ANSWER

The request-reply is just sending the received message to the request endpoint, and then blocking the current thread until a message arrives to the reply endpoint with a correlation id that matches the correlation id that was sent to the request endpoint.

We can summarize it as a synchronous emulator for asynchonous endpoints. In the example you give, you could probably simplify the same leveraging the mule reply to header.

0
On

Here I tried and got the answer of my question with code please have a look at this , i am printing Thread ID that will give clear picture how its working.

<?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>