Overview of VM Connector
The Anypoint Connector for Virtual Machine (VM Connector) facilitates intra-app and inter-app communication via asynchronous queues that are either transitory or persistent:
- Although transient queues are faster than permanent queues, they are unreliable in the event of a system failure.
- Consistent queues are more time-consuming, but they are more reliable.
Persistent queues work by serializing and saving the data on the disc while executing a Mule application in single runtime instance mode. When the Mule program runs in cluster runtime instance mode, the persistent queues are backed up in the memory grid. As a result, when a flow utilizes VM Connector to publish content to a queue, the Mule runtime engine decides whether to process the message in the same origin node or send it to the cluster to choose another node to handle it. The use of a VM Connector makes load distribution easier throughout a cluster.
While using persistent queues, the data you transfer must be serializable in either single or cluster runtime instance mode. Kryo has some limitations, despite the fact that you can enable serialization to acquire a greater set of serializable variables.
Take your career to next level in Mulesoft with HKR, Enroll now to get Mulesoft certification course training
While working with persistent queues, keep the following in mind:
- Keep your values simple since complicated structures that are difficult to serialize may result in performance issues or serialization errors.
- Ascertain that complicated Java objects implement the "Serializable" interface and follow the JavaBean contract.
- Use only maps, JSON objects, streams, and other similar objects if the accompanying values adhere to the preceding guidelines.
Prerequisites
You should be acquainted with the following before using this connector:
- Connectors for Anypoint.
- Engine for Mule's runtime.
- Mule flow Global elements and elements.
- Using Anypoint Studio for creating a Mule application.
You should have access to Anypoint Studio before you can create an app.
Typical Connector Use Cases
When you need to do the following, use VM Connector:
- Instead of utilizing a
directly, send messages from one flow to another via a queuing mechanism. - Work should be distributed over a cluster.
- Different applications running in the same Mule domain can communicate with each other.
- Simple queueing doesn't necessitate the use of a full JMS broker.
Examples of VM Connector in Mule:
See the examples provided for connection operations to get the most out of Anypoint Connector for Virtual Machine (VM Connector):
- Dynamic Routing:
Configure an operation “Publish” so that messages are dynamically routed to different queues based on conditions. - Message Attributes Propagation
Configure the Publish operation and the Listener source to propagate message attributes via the message payload through a VM queue. - Sending Messages across various applications
For communicating messages across many apps, set up the Publish, VM Listener, and Consume operations. - Publishing and Listening to Messages
To publish a message that is received by a separate flow, use the Publish operation and the Listener source. - Publishing a Message and Getting a Response
To send a message and receive a response, use the Publish consumption operation.
Mulesoft Training Certification
- Master Your Craft
- Lifetime LMS & Faculty Access
- 24/7 online expert support
- Real-world & Project Based Learning
Using Studio to create a Mule application and configure the connectors
Mule applications, properties, and configuration files can all be designed and updated using Anypoint Studio editors.
For adding and setting up a connector in Studio, follow these steps:
- Begin by creating a Mule project.
- In your Mule project, add the connector.
- Setup a source for the flow of the connector.
- In the flow, add a connector operation.
- For the connector, set up a global element.
You may see the app log to verify for issues when you run the connection, as explained in View the App Log.
Creating a Mule Project
Create a new Mule project in Studio and add and set up the connector there:
- Choose File -> New -> Mule Project from the File menu in Studio.
- Click Finish after giving your Mule project a name.
Adding a Connector to the Mule Project
Populate the XML automatically by adding VM Connector to your Mule project with the namespace of a connector and schema location and for adding the necessary dependencies to the “pom.xml” file in the project.
- Click “(X) Search in Exchange” in the “Mule Palette” view.
- Type “VM connector” in the search field of the “Add Dependencies to Project” window.
- In the "Available modules" option, select "VM Connector."
- Click “Add”.
- Click “Finish”.
When you add a connection to a Mule project in Studio, it isn’t available to other Studio projects.
Top 70 frequently asked Mulesoft interview questions & answers for freshers & experienced professionals
Configuring a Source
A source initiates a flow when a certain condition is met. You might use one of the following input sources with VM Connector:
- VM Listener, which starts a flow by listening to a VM queue.
- The HTTP Listener initiates a flow whenever it receives a request on the specified port and host.
- A scheduler begins a flow whenever a time-based condition is met.
For example, to configure a VM Listener source, perform these steps:
- Select "VM -> Listener" from the "Mule Palette" view.
- Drag “Listener” to the Studio canvas.
- Change the “Display Name” field value on the “Listener” configuration screen.
- To set up a VM queue that may be utilized by all instances of the “Listener” source and other VM Connector operations in the app, click the plus symbol (+) next to the “Connector configuration” field.
- Define the virtual machine queue.
- Set the "Number of consumers" field on the "Listener" configuration screen to the desired value (default is 4).
- Select a “Queue name” from the drop-down menu in the “Queue” section. The “Queue name” value displays automatically when you already built a VM queue earlier.
- Set the Timeout value (default is 5).
- From the drop-down menu, choose a Timeout unit.
Subscribe to our YouTube channel to get new updates..!
Adding a Connector Operation to the Flow
When you add a connection operation to your flow, you specify the operation that the connector will perform.
Follow these procedures to add an operation to VM Connector:
- Select “VM Connector” from the “Mule Palette” view, then the required operation.
- On the Studio canvas, drag the operation to the right of the input source.
[Related article: mule connectors]
Configuring Connector Global Element
It's ideal to set a global element that all instances of that connection in the app may utilize when configuring a connector. The queues on which the VM Connector operates are defined by the global configuration of the connector. You may specify as many configurations as you like, each with its own queue sets.
Only activities referencing that specific VM Connector setup can use each queue established within it. A queue name could not be repeated across configurations, and there can't be two queues with the same name in the same app or domain.
Follow these steps to configure the global element for VM Connector:
- In the Studio canvas, choose the connector's name.
- To access the global element configuration fields, click the plus symbol (+) next to the "Connector configuration" field in the operation's configuration screen.
- Select one of the following options from the Queues drop-down menu in the General section:
- Bean reference
Add your chosen reference value to the “Bean reference” field. - Edit inline
To create a new queue, click the plus symbol (+) in the "Queues" field. Then provide a value for "Queue name," choose either TRANSIENT (Default) or PERSISTENT for "Queue type," and enter a number for "Max outstanding messages" before clicking Finish.
- Optionally configure a reconnection strategy in the “Connection” section.
- Configure an expiry policy on the “Advanced” tab if necessary.
- Click “OK”.
The screenshot below gives an example of how to configure the VM Connector:
An example of setting the VM queue is shown in the following screenshot:
The VM Connector setup in the XML editor appears like this:
Viewing the Log of an App
You may look at the app log to see if there are any problems:
- The output is displayed in the Anypoint Studio console window when you're executing the app from Anypoint Platform.
- The app log is displayed in your OS console when you're executing Mule from the command line to execute the app.
You can also view the app log in the default location MULE_HOME/logs/
Lets's get started with Mulesoft Tutorial online!
Conclusion
This session on VM connector in Mule has now reached its end, after completing the prerequisites and experimenting with templates and examples, you're ready to use Anypoint Studio to develop your app and set up the connector.
About Author
Kavya works for HKR Trainings institute as a technical writer with diverse experience in many kinds of technology-related content development. She holds a graduate education in the Computer science and Engineering stream. She has cultivated strong technical skills from reading tech blogs and also doing a lot of research related to content. She manages to write great content in many fields like Programming & Frameworks, Enterprise Integration, Web Development, SAP, and Business Process Management (BPM). Connect her on LinkedIn and Twitter.
Upcoming Mulesoft Training Certification Online classes
Batch starts on 25th Nov 2024 |
|
||
Batch starts on 29th Nov 2024 |
|
||
Batch starts on 3rd Dec 2024 |
|