For BE/B.Tech/BCA/MCA/ME/M.Tech Major/Minor Project for CS/IT branch at minimum price Text Message @ 9424820157

VM Connector in Mule 4

VM component in Mule 4


We use VM because:
1) The Virtual Machine (VM) connector handles intra-app and inter-app communication through asynchronous queues that can be transient or persistent.
2) Transient queues are faster than persistent queues, but they are not reliable in the case of a system crash.
3) Persistent queues are slower but reliable.
4) When running on a single instance, persistent queues work by serializing and storing the contents on the disk.


When to Use the VM Connector: 
1) When you want to pass messages from one flow to another through a queuing mechanism, instead of using <flow-ref /> directly.
2) When you want to distribute work across a cluster.
3) When you want to communicate with different apps that are running in the same Mule domain.
4) When you need simple queuing that does not justify a full JMS broker.


Components in VM:
1. Publish: Publish the content to the queue
2. Listen: It listens to the VM queues
3. Consume: Pull one message from a queue. If the message is not immediately available, a message will wait up to configured queue timeout.
4. Publish Consume: Publishes the given content into a queue and then awaits up to the queue timeout for a response to be supply on a temporal reply- to queue that this operation automatically creates.

The flow of Publish:


Publish component configuration:


Connector configuration:


Flow of listener:


Method: GET

Input:

Output:

So, you can see clearly that the process is asynchronous and separate threads are executing for both the flows.
The first thread is executing loggers before VM and after VM and the second thread is executing payload logger that is Hello.

The flow of publish consume:

The flow of listener:

Method: GET

Output:
Here you can see the same thread is executing all the loggers one after one.


XML project code:


<?xml version="1.0" encoding="UTF-8"?>
<mule xmlns:sockets="http://www.mulesoft.org/schema/mule/sockets" 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:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="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
http://www.mulesoft.org/schema/mule/sockets http://www.mulesoft.org/schema/mule/sockets/current/mule-sockets.xsd">
     <vm:config name="VM_Config" doc:name="VM Config" doc:id="162fd81e-d7e3-4443-b95c-068f452be47b">
          <vm:queues >
              <vm:queue queueName="vm" />
          </vm:queues>
     </vm:config>
     <http:listener-config name="HTTP_Listener_config" doc:name="HTTP Listener config" doc:id="f34f130a-ff45-41df-a8b0-e5a1192329a4" >
          <http:listener-connection host="0.0.0.0" port="8085" />
     </http:listener-config>
     <flow name="test_vmFlow" doc:id="7cd43a2d-0bec-400a-93e7-92f1fd6bf145" >
          <http:listener doc:name="Listener" doc:id="f941a0ea-db90-471d-97b4-b94002d4c608" config-ref="HTTP_Listener_config" path="/vm"/>
          <logger level="INFO" doc:name="Logger" doc:id="9675b9e8-d6b2-4720-9f68-3ab0094ea9e9" message="before vm"/>
          <vm:publish queueName="vm" doc:name="Publish" doc:id="9df15d7a-792a-40a8-ad13-96ed7108475e" config-ref="VM_Config" sendCorrelationId="ALWAYS">
          </vm:publish>
          <logger level="INFO" doc:name="Logger" doc:id="cbcf0b10-3a48-43d5-ba7b-c5dec877a457" message="after vm"/>
     </flow>
     <flow name="test_vmFlow1" doc:id="69cd8eb2-0fd5-408c-bc25-251c40249198" >
          <vm:listener queueName="vm" doc:name="Listener" doc:id="30fd3738-201b-4428-8e90-42140ec82688" config-ref="VM_Config"/>
          <logger level="INFO" doc:name="Logger" doc:id="106b97e9-9be5-462c-8303-dffc60777e85" message="#[payload]"/>
     </flow>
     <flow name="test_vmFlow2" doc:id="46726825-5875-41b8-b498-47a3622c00fa" >
          <http:listener doc:name="Listener" doc:id="34fdd984-c2db-4235-852a-e052a542ec8b" config-ref="HTTP_Listener_config" path="/vm1"/>
          <logger level="INFO" doc:name="Logger" doc:id="3c4cd112-9d94-4e1f-9316-2f9aca97df8d" message="before vm"/>
          <vm:publish-consume queueName="vm" doc:name="Publish consume" doc:id="23ca2046-49d1-4786-b6b4-e412296d031b" config-ref="VM_Config"/>
          <logger level="INFO" doc:name="Logger" doc:id="76f7a5a4-b3e2-4639-a6f1-882c3c08a418" message="after vm"/>
     </flow>
     <flow name="test_vmFlow3" doc:id="46cf614a-3464-49ee-b378-323d93dbe09f" >
          <vm:listener doc:name="Listener" doc:id="26f18453-7287-46ea-bd4e-a47bce7af9b5" config-ref="VM_Config" queueName="vm"/>
          <logger level="INFO" doc:name="Logger" doc:id="149cf101-6bb7-4f1d-840e-150ba1e6a780" message="#[payload]"/>
     </flow>
<!--      <flow name="test_vmFlow1" doc:id="d2781c31-b6e2-4394-883c-f7afc844ecd1" >
          <vm:listener queueName="vm" doc:name="Listener" doc:id="62ab05f9-3adc-4ff4-a646-58603c2b719f" config-ref="VM_Config"/>
          <logger level="INFO" doc:name="Logger" doc:id="9c30c72f-51a6-49f4-8d63-9d1be38cc32b" message="after vm #[payload]"/>
     </flow> -->
</mule>

No comments:

Post a Comment



Please go through below tutorials:


Mule 4 Tutorials

DEPLOY TO CLOUDHUB C4E CLIENT ID ENFORCEMENT CUSTOM POLICY RABBIT MQ INTEGRATION
XML TO JSON WEBSERVICE CONSUMER VM CONNECTOR VALIDATION UNTIL SUCCESSFUL
SUB FLOW SET & REMOVE VARIABLE TRANSACTION ID SCATTER GATHER ROUND ROBIN
CONSUME REST WEBSERVICE CRUD OPERATIONS PARSE TEMPLATE OBJECT TO JSON LOAD STATIC RESOURCE
JSON TO XML INVOKE IDEMPOTENT FILTER FOR EACH FLAT TO JSON
FIXWIDTH TO JSON FIRST SUCCESSFUL FILE OPERATIONS EXECUTE ERROR HANDLING
EMAIL FUNCTIONALITY DYNAMIC EVALUATE CUSTOM BUSINESS EVENT CSV TO JSON COPYBOOK TO JSON
CHOICE ASYNC

Widely used Connectors in Mule 3

CMIS JETTY VM CONNECTOR SALESFORCE POP3
JMS TCP/IP WEBSERVICE CONSUMER QUARTZ MONGO DB
FILE CONNECTOR DATABASE CONNECTOR


Widely used Scopes in Mule 3

SUB FLOW REQUEST REPLY PROCESSOR CHAIN FOR EACH CACHE
ASYNC TCP/IP COMPOSITE SOURCE POLL UNTIL SUCCESSFUL
TRANSACTIONAL FLOW

Widely used Components in Mule 3

EXPRESSION CXF SCRIPT RUBY PYTHON
JAVASCRIPT JAVA INVOKE CUSTOM BUSINESS EVENT GROOVY
ECHO LOGGER


Widely used Transformers in Mule 3

MONGO DB XSLT TRANSFORMER REFERENCE SCRIPT RUBY
PYTHON MESSAGE PROPERTIES JAVA TRANSFORMER GZIP COMPRESS/UNCOMPRESS GROOVY
EXPRESSION DOM TO XML STRING VALIDATION COMBINE COLLECTIONS BYTE ARRAY TO STRING
ATTACHMENT TRANSFORMER FILE TO STRING XML TO DOM APPEND STRING JAVASCRIPT
JSON TO JAVA COPYBOOK TO JSON MAP TO JSON JSON TO XML FLATFILE TO JSON
FIXWIDTH TO JSON CSV TO JSON


Widely used Filters in Mule 3

WILDCARD SCHEMA VALIDATION REGEX PAYLOAD OR
NOT MESSAGE PROPERTY MESSAGE IDEMPOTENT FILTER REFERNCE
EXPRESSION EXCEPTION CUSTOM AND


Exception Strategy in Mule 3

REFERENCE EXCEPTION STRATEGY CUSTOM EXCEPTION STRATEGY CHOICE EXCEPTION STRATEGY CATCH EXCEPTION STRATEGY GLOBAL EXCEPTION STRATEGY


Flow Control in Mule 3

CHOICE COLLECTION AGGREGATOR COLLECTION SPLITTER CUSTOM AGGREGATOR FIRST SUCCESSFUL
MESSAGE CHUNK AGGREGATOR MESSAGE CHUNK SPLITTER RESEQUENCER ROUND ROBIN SOAP ROUTER