Basic Example Using VM Component
Introduction We can use the Java Virtual Machine (VM) transport for intra- JVM communication between Mule flows. This transport by default uses in-memory queues but can optionally be configured to use persistent queues.
FLOW
XML: <?xml version="1.0" encoding="UTF-8"?> <mule xmlns:http="http://www.mulesoft.org/schema/mule/http" xmlns:vm="http://www.mulesoft.org/schema/mule/vm" 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.4.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/vm http://www.mulesoft.org/schema/mule/vm/current/mule-vm.xsd http://www.mulesoft.org/schema/mule/http http://www.mulesoft.org/schema/mule/http/current/mule-http.xsd"> <flow name="VMFlow1" doc:name="VMFlow1"> <http:inbound-endpoint exchange-pattern="request-response" host="localhost" port="8080" path="VM" doc:name="HTTP"/> <logger message="--Main flow triggered " level="INFO" doc:name="Logger"/> <vm:outbound-endpoint exchange-pattern="request-response" path="subflow" doc:name="VM"/> </flow> <flow name="VMFlow2" doc:name="VMFlow2"> <vm:inbound-endpoint exchange-pattern="request-response" path="subflow" doc:name="VM"/> <logger message="--Hello world" level="INFO" doc:name="Logger"/> </flow> </mule>
Execution: Service will trigger from URL “http://localhost:8080/VM” Service will display :‘Hello world’
 The in memory (VM) transport has two modes of operation: One for use with request-response and another for use with one-way endpoints.  request-response:  When using request-response endpoints, messages are delivered directly from an outbound vm endpoint to the inbound vm endpoint that is listening on the same path. This delivery is blocking and occurs in the same thread. If there is no inbound request-response VM endpoint in the same Mule application that is listening on this path, then dispatching a message from the outbound endpoint fails.  one-way:  When using one-way endpoints, messages are delivered to the corresponding inbound endpoint via a queue. This delivery is non-blocking. If there is no inbound one-wayendpoint in the same Mule application listening on this path, then, although dispatching of the message succeeds, the message remains in the queue. By default, this queue is in memory, but it is also possible to configure a persistent queue that uses the file system as its persistence mechanism.
References  https://docs.mulesoft.com/mule-user-guide/v/3.7/vm- transport-reference#vm-transport-info

Basic example using vm component

  • 1.
  • 2.
    Introduction We can usethe Java Virtual Machine (VM) transport for intra- JVM communication between Mule flows. This transport by default uses in-memory queues but can optionally be configured to use persistent queues.
  • 3.
  • 4.
    XML: <?xml version="1.0" encoding="UTF-8"?> <mulexmlns:http="http://www.mulesoft.org/schema/mule/http" xmlns:vm="http://www.mulesoft.org/schema/mule/vm" 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.4.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/vm http://www.mulesoft.org/schema/mule/vm/current/mule-vm.xsd http://www.mulesoft.org/schema/mule/http http://www.mulesoft.org/schema/mule/http/current/mule-http.xsd"> <flow name="VMFlow1" doc:name="VMFlow1"> <http:inbound-endpoint exchange-pattern="request-response" host="localhost" port="8080" path="VM" doc:name="HTTP"/> <logger message="--Main flow triggered " level="INFO" doc:name="Logger"/> <vm:outbound-endpoint exchange-pattern="request-response" path="subflow" doc:name="VM"/> </flow> <flow name="VMFlow2" doc:name="VMFlow2"> <vm:inbound-endpoint exchange-pattern="request-response" path="subflow" doc:name="VM"/> <logger message="--Hello world" level="INFO" doc:name="Logger"/> </flow> </mule>
  • 5.
    Execution: Service will triggerfrom URL “http://localhost:8080/VM” Service will display :‘Hello world’
  • 6.
     The inmemory (VM) transport has two modes of operation: One for use with request-response and another for use with one-way endpoints.  request-response:  When using request-response endpoints, messages are delivered directly from an outbound vm endpoint to the inbound vm endpoint that is listening on the same path. This delivery is blocking and occurs in the same thread. If there is no inbound request-response VM endpoint in the same Mule application that is listening on this path, then dispatching a message from the outbound endpoint fails.  one-way:  When using one-way endpoints, messages are delivered to the corresponding inbound endpoint via a queue. This delivery is non-blocking. If there is no inbound one-wayendpoint in the same Mule application listening on this path, then, although dispatching of the message succeeds, the message remains in the queue. By default, this queue is in memory, but it is also possible to configure a persistent queue that uses the file system as its persistence mechanism.
  • 7.