MuleSoft Core Components and Configuration Tutorial
MuleSoft is the world’s #1 API and integration platform. It helps businesses unlock and unify data, enable connectivity, accelerate the creation of connected activities, and increase efficiency. MuleSoft comes with all the ETL tools you need to connect to data sources, extract and process real-time data, and send it across multiple channels. Read our tutorial to learn everything you need to know about its core components and how you can get the best out of the platform.
Table of Contents
The core components in Anypoint Studio serve as crucial building blocks for creating and executing Mule flows. As a Mule event moves through the app in a series of linked phases, the core components provide the logic for processing it and enable the completion of a business scenario. They can be accessed and used by clicking on the core tab in the Mule Palette.
The core components of the Anypoint platform can be split into various groups based on their type and task. These groups include Endpoints, like the Scheduler, for example, which triggers a Mule event initiated at a previously configured time interval. There are also Error Handling components that handle, route, and process any negative scenarios and errors in a Mule application, such as On Error Continue and On Error Propagate.
To process Mule messages in batches, instead of processing them all together, you can use Batch components, which include:
- Batch Aggregator
- Batch Job
- Batch Step
1. Custom business events – this component primarily collects metadata about flows, message processors, and business transactions in a MuleSoft app. It gathers data and evaluates KPIs relevant to the business logic executing within the flow.
2. The Dynamic Evaluate component allows selecting a Dataweave script based on evaluating a script and then executing the selected script to generate specific results instead of simply hardcoding in a Transform Message Component.
3. The Flow Reference component enables the routing of the Mule event to another flow or sub-flow synchronously by executing the flow until reaching the flow reference. Next, the event executes the components in the referenced flow from beginning to end. After executing the referenced flow, the event returns to the main flow. Constructing such flow enables splitting the logic of the flow into smaller, reusable units.
There are a couple of considerations when using this component, though most of them pertain to the target variables as well as the error-handling behavior.
- By setting the target variable in the flow reference, the original message remains the same. The modifications of the payload in the referenced flow will also revert to the initial state, including the defined variables. On the contrary, by not setting the target variable in the flow reference configuration, the modifications done to the payload will remain while the original message will change.
- In case of an error in the referenced flow, the execution of the components stops, and the calling flow becomes the listener. The error from the referenced flow will be bubbled up to the main flow and handled there depending on the defined error handling strategy.
4. The Logger Component helps monitor and debug MuleSoft applications by preserving important information regarding the execution of a Mule flow. Such data could include error messages, notifications, incoming payload, or attributes. You can add it wherever you need it in the flow and configure it with any combination of strings and DataWeave expressions.
5. The Transform Message component is one of the most utilized components in Mule flows. As the name suggests, it transforms input data into a new output structure and/or format. It contains a visual mapper that can drag and drop elements from the incoming data structure, or it can be specifically written in a transformation script with DataWeave.
The supported data formats are:
The Scheduler component enables triggering a flow based on a pre-defined time frame. Once the condition is met, the flow will start executing. You can set it at a regular interval or with a more flexible cron expression. It is worth mentioning that the Scheduler conforms to the time zone where the Mule runtime is set up. However, if the application is running In Cloudhub, the Scheduler is set in the UTC zone, regardless of the geographic location.
There are two types of errors in a MuleSoft application: system errors and messaging errors. If no error handling is set, the default error-handling mechanism takes care of the error, which is basically logging and error propagation. However, setting up On-Error Components inside the flow’s built-in Error Handling component allows the use of any number of MuleSoft components to process and handle that error.
The two most crucial error-handling scopes are:
- On Error Propagate
- On Error Continue
The business scenario and the desired outcome decide which scope needs to be used. In any case, the flow execution stops, and the components defined in the error strategy will be executed. The main difference is that the On Error Propagate scope will propagate the error to a higher level causing a failure at that level, while On Error Continue will execute the component in the error scope. Finally, that result will return to the owner as a successful response.
We use these MuleSoft components to process an input event and direct it to one or more separate routing flows where sequences of different components will be executed.
1. The Choice Router component routes Mule messages to a flow based on a set of DataWeave expressions, which evaluate message content. The idea is to add a conditional message processing, and each DataWeave expression is connected to one route. The message will be routed to the first condition, where the expression will evaluate as true.
2. The Scatter-Gather component is a routing event processor that processes a Mule event through parallel processing routes that contain different even processors. Each of these routes happens in a separate thread as a new event. The result of this processing can be either the same Mule event without modifications or a new one with its own payload, attributes, and variables. After the processing finishes, the Scatter-Gather component will combine the events returned by each processing route into a new Mule event passed to the next processor only in case of successful processing in each route.
Each of the defined routes starts with the same initial variable values, and any modification within a route does not affect other routes. If a variable is added or modified by multiple routes, the values enter a list of all values added to that variable within all routes. A route will only define the value when it is single.
In terms of error handling, a Try Scope is used to handle any errors that might occur while processing a specific route. In case of any error after processing finishes, the Scatter-Gather component detects a MULE:COMPOSITE_ROUTING error and the execution of the process stops. Then the flow is branched out to its error Handling component. Since the MULE:COMPOSITE_ROUTING object contains the errors and the result from the successfully processed routes, the logic in the error handling scope of the flow can be set to use those results for further processing.
These types of components enable grouping a sequence of event processors to apply a specific programming behavior to that isolated set of processors.
The components include:
- For Each
- Until Successful
For Each Scope – this component enables the payload to split into elements and process each element individually through the components defined in the scope. This element is like that for each loop in any programming language and can process any collection, including lists and arrays, by supporting content types like application/json, application/java, and application/xml. During the iteration, each scope stores each item processed in the payload.
You can use the following transformer components to set, change, or remove part of a Mule event:
- Remove Variable
- Set Payload
- Set Variable
1. Set Payload Component – This component aims to update the payload of the Mule message via a literal string or a DataWeave expression. It is commonly used for simple expressions and little to no transformations.
2. Set Variable Component – The purpose of this component is to create or update a variable that stores values from the Mule event you can use throughout the execution of the flow. This is done via a literal string or a DataWeave expression. We recommend using it for simpler transformations.
That stores values from the Mule event you can use throughout the execution of the flow. This is done via a literal string or a DataWeave expression. We recommend using it for simpler transformations.
The Mule Palette offers numerous out-of-the-box components, which can be used in the execution of the MuleSoft applications flows. The usage of these components depends on the necessary logic and the expected result, which vastly facilitates and accelerates the development process.
Scalefocus has extensive experience utilizing MuleSoft for various types of integrations. Our expertise in complex enterprise projects has enabled us to leverage the platform and help our partners with their MuleSoft API integration.
We offer implementation and consultancy that will allow you to not only start learning MuleSoft but increase productivity and agility while cutting operational costs, so do not hesitate to get in touch!