|Variable in Mule 4
In this Variable in Mule 4 tutorial we will look how we can create and use mule variable in Mule 4, and how it is different from Mule 3 and Mule 4.
In Mule 3 we had Flow variables, Session variables and record variable to store the data inside mule flow. But now in Mule 4 this has been changed; session variable and record variable has been removed and there is only Flow Variable.
As in Mule 3, Flow Variable in Mule 4 value is lost even when the flow crosses the transport barrier.
In Mule 4, flow variables have been enhanced to work efficiently during batch processing, just like the record variables. Flow variables created in batch steps are now automatically tied to the processing record and stays with it throughout the processing phase. No longer record variables are needed.
In case we want our Dataweave expression outside mule project, load and process it at runtime then you would need Dynamic Evaluate component.
In a scenario wherein dataweave mapping conditions are expected to change frequently based on client’s requirements and you don’t want to redeploy running APIs again and again, in such scenario we can store our dataweave expression in a DB or S3 or other location and access and process it dynamically in our Mule API. Any changes made to this external datawave will be picked up by Mule while reading it from external source and processed.
In the below example we are using variable dynamic_dw to store the datawave expression as a String. In a real world this datawave expression should be coming from an external source like DB or SFTP or others and getting stored in a variable.
<sub-flow name="dynamic-evaluateSub_Flow" doc:id="2145c3c0-5196-418f-9dd3-adf06966cc4a" > <set-variable value="#[%dw 2.0 output application/json --- payload]" doc:name="Store payload" doc:id="18b55a69-28fd-48ae-9344-f80e9be3ffc6" variableName="reqReceived"/> <set-variable value="#['%dw 2.0 output application/json --- vars.reqReceived.username']" doc:name="datawave received from external source" doc:id="29aebfba-73e4-41b3-9f3f-e508f98da413" variableName="dynamic_dw"/> <logger level="INFO" doc:name="datawave received" doc:id="672895f7-42e8-4c25-8dca-b11bd61634b3" message="#['script - ' ++ vars.dynamic_dw]"/> <ee:dynamic-evaluate doc:name="Dynamic Evaluate" doc:id="59d877bb-36ba-4193-bf72-df5083a06d22" expression="#[vars.dynamic_dw]"/> <logger level="INFO" doc:name="output" doc:id="fea7a7e5-b8d3-4726-80b8-a846c3794a71" message="#[payload]"/> </sub-flow>
DataWeave is a new feature of Mule-3 that allows us to convert data to any kind of format, such as XML, CSV, JSON and POJO’s etc. In Mule 3, we use both MEL and Dataweave for writing the mule messages. Among these, MEL is default expression language in Mule 3 But this approach had some data inconsistencies and scattered approaches. To avoid the stress of converting data objects to Java objects in Mule 3 every time by the usage of expressions Mule 4 was launched. In Mule 4 DataWeave is the default expression language over Mule 3’s default MEL.
In Mule-4 DataWeave version has changed from 1.0 to 2.0.
Apart from syntax changes, there are many new features in DataWeave 2.0
|Externalizing Common Mule Flows
In this tutorial we will be externalizing some common mule flows so they can be used by multiple Mule Applications
Externalizing common mule flows can be achieved by exporting the flows to be externalized into a JAR file and then importing the JAR in other applications. Tells look on the details of how we can do this with just few steps.
|1. Understanding the Flow
In the flow below we want to externalize sub flow – “externalizeMuleAPISub_Flow” which is been called by Flow reference in Get and Post Flows and exception handling – “externalizeMuleAPI-apiKitGlobalExceptionMapping”.
|2. Creating new Mule project
We need to create a new mule project and dump the mule common flows that we want to externalize into it. And remove copied code from our previous project.
Here we have deleted and added the 2 flows from our old project into our new project.
|3. Exporting the new project as JAR file.
Here are the steps to be followed to export the project as JAR.
Right Click on the Project in Package Explorer >> Click Export
In the Popup Window Select Java>Jar File and Click Next.
Select The project to be exported “externalflows” and add the path where the JAR is to be saved and Click Finish.
Now, we have create the project with common flows as Jar and export it to the specified location.
|4. Importing the JAR file
Now after exporting JAR, we need to import it to our main project.
To Import the Jar -> go to Project Properties and Click “Add External Jars” and select the JAR File.
|5. Adding the Common Flows
Now we need to add the mule XML file name that we have imported as JAR into our main project.
|6. Running the Code
You might see few error been reported by Mule even after adding the mule XML filename. But do not worry on building the application all the error will go off.
MuleSoft or Mule ESB interview Questions
Here are the 18 most important and common mulesoft or mule esb interview questions and answers which are bound to be asked in any Mule ESB interview. Whether it’s Mulesoft or Mule ESB interview with Accenture, Cognizant, Infosys, Deloitte or any company below Mule ESB interview questions are always always been asked. You can easily clear any Mulesoft or Mule ESB interview questions if you learn answers to these Mule ESB questions.
|1. What are Web Services?
Web service is a function or program in any language that can be accessed over HTTP. Message format can be XML or JSON or any other program as long as the other programs can understand and communicate. Web services can be synchronous or asynchronous. Any web service has server-client relationship. Any web service can have multiple clients. Eg: When a travel portal is selling tickets of an airliner, Portal is client and the Airline is the server as it is selling its service. Continue reading
MuleSoft or Mule ESB interview Questions
Here are the most important and common mulesoft or mule esb interview questions and answers which are bound to be asked in any Mule ESB interview. Also see Mule Interview Questions I.
|1. What are inbound and Outbound properties ?
Inbound properties are immutable, are automatically generated by the message source and cannot be set or manipulated by the user. They contain metadata specific to the message source. A message retains its inbound properties only for the duration of the flow; when a message passes out of a flow, its inbound properties do not follow it.
RAML Interview Questions.
In this mule tutorial, here are the most important and common RAML interview questions and answers which are bound to be asked in any Mule ESB interview.
|1. What is RAML and why we use it?
RAML – RESTful API Modeling Language
|2. Who can you import RAML in your poject?
|MuleSoft Validation Framework – Handling Business Errors
In this tutorial of mulesoft validation we will create an exception handling framework that will generate business/logical error and do custom validations to request/response message while mapping mulesoft code and learn how to handle those error.
The validations are:
The above example, can be resolved in couple of ways and we will see one of the most simplest and easy way by creating validation framework.
|MuleSoft Scatter-Gather Scope
In this tutorial we will look at various configuration properties of Scatter-Gather with examples in detail and also see how to handle exception in Scatter-Gather.
Why use Scatter-Gather in Mulesoft:
Caching In Mule ESB or Cache Scope
In this Mule ESB tutorial we will look into what is caching and why to use it, how can we implement caching in mulesoft project and configuration properties in Mule Cache Scope/Activity. Also a step by step configuration of mule cache scope/activity and how to cache information retrieved from database. Please refer to Mule Tutorial: Connecting with Database mule tutorial to know how to connect to database in Mule ESB.
|What is caching and why to use it?
Caching is a concept with is used to store frequently used data in the memory, file system or database which saves processing time and load if it would have to be access from original source location every time.
For example: We have to create an API to retrieve user information, that has connect to an external database which is on different server and fetch the records. (Assumption: external DB is not changing frequently)
|Mulesoft / Mule EBS – Mule Flows Tutorial|
In this mule ESB tutorial we will understand various mule flows in detail with downloadable examples.
|Various types of flows in mule
There are 4 types of flows in mule. While creating these flows the flow name should be unique in whole mule project despite beaning in different mule application XML file.
Use – It can be used to split common logic and be reused by other flows.
Creating Mule Project with RAML
In this Mule tutorial we will learn how to create Mule project with RAML and a detailed walk-through on how the Mule flow works in case of a success or error scenario:
|Mule ESB – What is RAML and why it’s used
RAML stands for RESTful API Modeling Language and is similar to WSDL. A RAML provides a structure to an API and also help the client who is invoking the API to know before hand what the API does.
A RAML contains:
Connecting with Database MySQL
In this Mulesoft / Mule ESB tutorial of Connecting with Database Using MySql, we will use mulesoft Database Connector and connect it with MySQL DB:
|MuleSoft Database Connector using MySQL
The Database connector allows you to connect with database with almost any Java Database Connectivity (JDBC) relational database using a single interface for every case. The Database connector allows you to run SQL operations on database including Select, Insert, Update, Delete, and even Stored Procedures. As of Anypoint Studio May 2014 with 3.5.0 Runtime, the JDBC connector is deprecated, and the Database connector takes on JDBC connection capabilities.
|In this Mulesoft / Mule ESB tutorial we will connect with Tibco EMS server Queue and send messages across:|
|Mule JMS Connector
Inbound – Mule JMS will receive the message and be used with an inbound endpoint.
<jms:outbound-endpoint queue="my.queue"/>; <jms:inbound-endpoint topic="my.topic"/>;