Mule ESB has been arguably the most popular and efficient open source Enterprise Service Bus (ESB) available in market and its rich options of connectors, routers, filters, error handlers, transformers supporting multiple languages like java, JavaScript, groovy, python and ruby has elevated it as the indisputable ESB of the digital era. In September 2016, Forbes released its first ever top 100 private cloud companies in the world and Mulesoft was ranked 20th in the report. Mulesoft was the only company to feature in both magic quadrants for Application Services Governance and Enterprise Integration Platform as a Service (iPaaS) in Gartner report released in April 2015 and March 2016 respectively. This highlights Mulesoft’s rapid growth and its stronghold in integration division helping organisations for the digital transformation.
Apache Groovy is a powerful object oriented programming language for Java platform. Its simplicity, dynamicity and easy to learn syntax had made it as the preferred scripting language for developers. We will implement groovy script in a Mule flow to demonstrate the smooth integration of groovy script in a Mule application.
Pre-Requisites:
- Basic working knowledge on Mule ESB development using Anypoint Studio.
- Basic knowledge on any object-oriented programming language is an added advantage.
In this simple example, we will build a Mule application with a HTTP listener which will be inputted with the below query parameters
- Name
- Parameter1
- Parameter2
The Mule application will be configured with a groovy component which will print the sum of parameter 1 and parameter 2 as the response.
Mule Flow:
HTTP Inbound Endpoint:
A HTTP inbound endpoint is created by dragging the HTTP connector component from the palette to the canvas. A HTTP connector configuration is created which will listen to localhost on port 8081 and the path in which the resource can be accessed will be “groovy”.
Session Variables:
We will have 3 session variable components to extract the query parameters from the input url and save it to session variables configured in the flow.
Groovy:
A groovy component is placed next to the session variable components in which we sum up the values of parameters passed.
Note: We need to use toInteger() function to convert the string into integer. When the query parameter is assigned to the session variable its data type is string. In order to convert the string to integer we use the toInterger() function.
Logger:
We will use a logger to log the values of the session variables in the console.
Set Payload:
We will place a Set Payload component to complete the Mule flow. The Set Payload component will print the message in the following format as output.
Hello “Name” !!! The sum of “Parameter1” and “Parameter2” is “Sum” !!!
Testing the Mule flow:
It’s time to test the Mule application we have built. We can use any browser or tools like SOAP UI and Postman Chrome plug-in which is capable of posting a HTTP request. Using chrome browser, try to post the following: localhost:8081/groovy?name=sudheer¶meter1=4¶meter2=65
Your writing style makes complex topics so easy to understand. Keep it up!
ReplyDeletePG Diploma In Clinical Research
Best Clinical Research Courses
Online clinical research courses in pune
Pharmacovigilance Syllabus
Great post! I thoroughly enjoyed reading it.
ReplyDeleteClinical Research Courses in Banglore
Clinical Research Courses in Nagpur
Clinical Research Courses in Amravati
"Brilliantly explained. Looking forward to more posts like this!"
ReplyDeleteMedical Coding Courses in Banglore
Medical Coding Courses in Pune
Medical Coding Courses in Nagpur
Medical Coding Courses in Amaravati
"A well-articulated blog with practical takeaways. Nicely done!"
ReplyDeletePharmacovigilance Courses in Mumbai
Eligibility for Digital Marketing Courses
Career in Pharmacovigilance