In this article, we will discuss the three Architectures (Monolithic, SOA, and Microservices) along with MuleSoft integrations (HTTP Connector v1.5.11) example.
In this working example, we will learn, how to create an application in Anypoint Studio. Here, we are going to create a simple mule project, which will expose REST API known as /welcome. It will accept HTTP Request and will return response “Welcome to – The Basic Tech Info” to the clients.
Basically, we are integrating HTTP Listener.
Anypoint Studio 7.4.2
Mule Server 4.2.2 EE
Java 1.8
Maven 3.5.0
HTTP Listener v1.5.11
We need Anypoint Studio, JDK and Maven for running below application on Mule 4 runtime or CloudHub instances.
Step 1. First install JDK 1.8
Step 2. Add the Java_Home/bin directory to your system’s PATH.
Step 3. After downloading Maven, extract it to a drive.
Step 4. Add the M2_Home/bin directory to your system’s PATH.
Step 5. Download and extract Mule Studio to a drive.
Step 6. Now start Mule Studio by clicking on AnypointStudio exe icon in the folder /AnypointStudio
Step 7. Once started, close the startup page
Step 8. In Mule Studio, go to Window -> Preferences. Expand Java, then click on Installed JREs. Add JDK 1.8 and select it. In expanded Java, click on Compiler and select the compiler level as 1.8
Step 9. Now expand Anypoint Studio and click on Maven Settings. Then select appropriate Maven installation home directory using Browse button.
Step 10. If you want you can input Default groupId for new projects, it will save your time every time when you want to create a new project.
Step 1. In Anypoint Studio, go to File -> New -> Mule Project
Step 2. Input Project Name: mule-http-listener-example, Runtime is by default selected, tick on Use Maven; here the artifactId is automatically picked up from the Project Name, the Group Id are picked up from the Default groupId for new projects and version is also a default value.
Step 3. Click Next and verify the JDK, mainly select Use default JRE(currently ‘zulu8’)
Step 4. Click on Next and click on Finish.
For adding Payload we need to drag and drop Set Payload transformer to our Mule message flow
Auto generated Configuration XML would be looked like as below.
<?xml version="1.0" encoding="UTF-8"?>
<mule xmlns:http="http://www.mulesoft.org/schema/mule/http" xmlns="http://www.mulesoft.org/schema/mule/core"
xmlns:doc="http://www.mulesoft.org/schema/mule/documentation"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.mulesoft.org/schema/mule/core http://www.mulesoft.org/schema/mule/core/current/mule.xsd
http://www.mulesoft.org/schema/mule/http http://www.mulesoft.org/schema/mule/http/current/mule-http.xsd">
<http:listener-config name="HTTP_Listener_config" doc:name="HTTP Listener config" doc:id="9870e986-1359-4fa0-b838-98086324fc86" >
<http:listener-connection host="0.0.0.0" port="8089" />
</http:listener-config>
<flow name="mule-http-listener-exampleFlow" doc:id="496fdf84-8f43-4409-aa50-fdf83d30a4a9" >
<http:listener config-ref="HTTP_Listener_config" doc:name="Listener" doc:id="74c8e8e9-d2d2-4df4-a184-f5e9c55c1375" path="/welcome"/>
<set-payload value="Welcome to - The Basic Tech Info" doc:name="Set Payload" doc:id="fc4efe51-55cc-4484-a2bb-abdf78741397" />
</flow>
</mule>
Note: Exception Handling we will learn in next blog with examples.
Just Right click on Mule Message Flow: mule-http-listener-example.xml and go to Run as -> Mule Application
It will launch Mule 4 runtime instance and application will be deployed on this.
MULE_HOME is set to D:\Software\AnypointStudio\plugins\org.mule.tooling.server.4.2.2.ee_7.3.5.202001031809\mule
MULE_BASE is set to D:\Software\AnypointStudio\plugins\org.mule.tooling.server.4.2.2.ee_7.3.5.202001031809\mule
--> Wrapper Started as Console
Launching a JVM...
Starting the Mule Container...
WrapperManager: Initializing...
Running Mule in testing mode
INFO 2021-07-29 00:13:19,543 [WrapperListener_start_runner] org.mule.runtime.core.internal.logging.LogUtil:
**********************************************************************
* *
* ((((((((((((((((((( *
* ((((( ((((# *
* &((( *((( *
* &((( ((( *
* ((( (((% (((# ((( *
* (( ((((((( ((((((( ((( *
* (( ((((((((( ((((((((( (( *
* (( #((((((((((( #((((((((((( ((( *
* #(( (((((((((((((( (((((((((((((( (( *
* (( (((((( /((((((( ((((((( /(((((( (( *
* (( (((((( (((((((&((((((( (((((( (( *
* (( ((((( ((((((((((((* (((((( (( *
* (( (((((( *((((((((( (((((( (( *
* (( (((((( ((((((( (((((( ((( *
* (( (((((( (((((( (( *
* ((# ((((((# ((((((( (( *
* ((# (((((((( (((((((( ((( *
* ((( ((((((( ((((( ((. *
* (( ((( ((( #(( *
* /(( ((( *
* ((( &((( *
* *((((& &(((( *
* ((((((((((((((/ *
* *
* ___ ___ _ ______ _ _ *
* | \/ | | | | ___ \ | | (_) *
* | . . |_ _| | ___ | |_/ / _ _ __ | |_ _ _ __ ___ ___ *
* | |\/| | | | | |/ _ \ | / | | | '_ \| __| | '_ ` _ \ / _ \ *
* | | | | |_| | | __/ | |\ \ |_| | | | | |_| | | | | | | __/ *
* \_| |_/\__,_|_|\___| \_| \_\__,_|_| |_|\__|_|_| |_| |_|\___| *
* *
* *
* Mule Runtime and Integration Platform *
* Version: 4.2.2 Build: e790fb3a *
* MuleSoft, Inc. *
* For more information go to *
* https://www.mulesoft.com/platform/soa/mule-esb-enterprise *
* *
INFO 2021-07-29 00:13:46,530 [WrapperListener_start_runner] [event: ] org.mule.runtime.core.internal.logging.LogUtil:
**********************************************************************
* Application: mule-http-listener-example *
* OS encoding: UTF-8, Mule encoding: UTF-8 *
* *
**********************************************************************
INFO 2021-07-29 00:13:46,533 [WrapperListener_start_runner] org.mule.runtime.core.internal.logging.LogUtil:
**********************************************************************
* Started app 'mule-http-listener-example' *
* Application plugins: *
* - Sockets : 1.1.5 *
* - HTTP : 1.5.11 *
**********************************************************************
INFO 2021-07-29 00:13:46,546 [WrapperListener_start_runner] org.mule.runtime.core.internal.logging.LogUtil:
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
+ Mule is up and kicking (every 5000ms) +
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
INFO 2021-07-29 00:13:46,568 [WrapperListener_start_runner] org.eclipse.jetty.server.AbstractConnector: Started ServerConnector@7f23e266{HTTP/1.1,[http/1.1]}{0.0.0.0:63929}
INFO 2021-07-29 00:13:46,571 [WrapperListener_start_runner] org.mule.runtime.core.internal.logging.LogUtil:
**********************************************************************
* - - + DOMAIN + - - * - - + STATUS + - - *
**********************************************************************
* default * DEPLOYED *
**********************************************************************
*******************************************************************************************************
* - - + APPLICATION + - - * - - + DOMAIN + - - * - - + STATUS + - - *
*******************************************************************************************************
* mule-http-listener-example * default * DEPLOYED *
*******************************************************************************************************
We need to hit following Http Url for testing our application, which is running on Mule 4 runtime instance.
Http Url: http://localhost:8089/welcome
To stop the application from running, click the red Terminate button in Studio’s Console.
CloudHub platform deploys MuleSoft application with a publicly accessible endpoint URL. Right-click on the project in Package Explorer, and click on Anypoint Platform -> Deploy to CloudHub.
It will ask for Anypoint’s credentials
Note: Choose the Sandbox environment then choose a unique name for your application. When your application name has a green check next to it, click the Deploy Application button. If your application has a red x next to it, it means someone else has deployed with that application name. It may take a few minutes to fully deploy to CloudHub.
Also, we can change Runtime version, Worker size, No. of Workers and Region. We will discuss about these configurations in next blog.
Have a fantastic day. Thank you for reading 🙂