what is transformers
Transformations are typically carried out using DataWeave, which is a powerful expression language for transforming data. DataWeave allows you to easily map and transform data from one format to another. It’s an integral part of MuleSoft’s Anypoint Platform, providing a way to handle data transformation within your integration flows.
transformers contains
- Set variable
- Set payload
- Remove variable
Here we see about the transformers one by one and how to use it in the flow. And i attach the screenshot’s of the flow which is given below.
Set variable
The Set
variable component allows you to set the value of a variable within a flow. You can do this by configuring the set variable component.
You can set a variable directly within a DataWeave transformation using the vars
keyword.
Here I attach the screen shoot of flow. where the set variable is used
Initially we open the workspace and drag and drop the consent components. The first set variable which contains the name as “varsA” and the value 10.
The second screen shoot which mention the second variable’s name as “varsB” and value 20.
Then finally we set the logger for to print the response value which we need after the hitting of the flow. Here I mention to need the value of “varsA”. I enable the ‘fx‘. so that only we access the value which we are used in the flow.
After hitting the we see the response in the console as. It gives as the value of 10 why because we call the function of “varsA”.
set payload
The Set Payload
component is used to set the message payload. The payload is the main content of the message, and by using the Set Payload
component, you can change or replace the existing payload with a new value.
The Set Payload
component is often used when you want to transform or update the content of the message payload within your Mule flow. It’s a straightforward way to manipulate the data being passed through your integration.
remove variable
The Remove Variable
component is used to remove a variable from the Mule message. This component is helpful when you want to clean up or remove a variable that you no longer need in your flow. Removing variables can be useful for managing memory and avoiding potential issues with variable clutter.
In this screen shoot mention that we use remove variable in the flow.
We use to join the remove variable in the previous flow of set variable. previously we select the value of “varsA” (ie) 10. By using set variable as same as we use remove variable to remove the same value for our understanding.
Once we hit the flow after completing the run configuration. we see the two different outputs. That are the first logger gives the value of “varsA” and the second logger gives the results as empty which means its remove the value from the flow.