Mule 4 Dynamic Evaluate Component
This article explains about Dynamic Evaluate Component in Mule which helps in executing dynamic dataweave scripts.
Join the DZone community and get the full member experience.Join For Free
- A behavior that allows you to dynamically select the dataweave script instead of hardcoding the script in the Transform Message component.
- This component lets you execute an expression that eventually evaluates a Dataweave script wherein the expression being executed here again results in a dataweave script.
- This way we can dynamically select the dataweave script to be executed concerning any varying parameter.
Assume we are in API led connectivity approach where we have
- A set of Experience APIs invoked by different applications like Salesforce, SAP, Mobile Apps, Web Apps, etc for the same functionality.
- A Process API to orchestrate the response coming from System API concerning source of the request.
- A System API which connects to backend systems like databases etc to get the required data.
All the client applications in our example may not require all the data retrieved from system API. So, in the process API orchestration if we had to respond to different client applications with different response structures, in the general case we will end up designing each flow for each client app to achieve this.
But using a dynamic evaluate component without using a choice router and without defining different flows respective to different client applications we can achieve this dynamic response.
Let us check the example in Anypoint studio
- Create a mule project
- Create dwl files as shown below specific to each Client Application
- Set below payload in Transform Message Component and assume it to act as a response from system API
- Create a mule variable to store the dynamic dataweave client-specific script using readUrl() in which dw file to be picked is based on the queryParam(appName) passed by the client application
- Configure Dynamic Evaluate Component to read the dynamic script and run on the payload.
- Final Mule Flow
Hope you understood the concept and the example, please provide feedback in the comments.
Published at DZone with permission of Praneeth Venishetty. See the original article here.
Opinions expressed by DZone contributors are their own.