Mule 4 + MuleSoft as Microservices Architecture + HTTP Connector + Example

In this article, we will discuss the three Architectures (Monolithic, SOA, and Microservices) along with MuleSoft integrations (HTTP Connector v1.5.11) example.

  • Monolithic Architecture (Single Unit)
  • SOA Architecture (Coarse-Grained)
  • Microservices Architecture (Fine-Grained)

What is Monolithic (Single Unit) Architecture?

  • It is also known as single unit tightly-coupled application.
  • It is executed in a single application layer and group all functionalities in the same layer.
  • The communication between resources and applications is direct without any other middleware/ESB.
  • For small architectures, it works well, but when the architecture grows, the application is more complex to manage and refactor.
  • In addition, it makes continuous integration more complicated and making the DevOps process almost impossible to accomplish. For example see the below diagram of CRM application.
Monolithic Architecture Example

What is SOA (Coarse-Grained) Architecture?

  • It is also known as Coarse-Grained architecture.
  • This is the original architecture of MuleSoft and Red Hat Jboss fuse, the ESB that allows to centralize all the business logic and allows the integrations between services and applications.
  • MuleSoft offers Mule Runtime (Mule 4). It is similar to Apache Tomcat, which works as a servlet container. For example see the below diagram of CRM application in SOA architecture.
Soa Architecture
  • As we learnt, the Red Hat Jboss Fuse ESB will be in charge of transforming the data, routing, accessing the necessary services, managing errors, etc. Similarly, MuleSoft is reponsible for transforming the data, routing, accessing the necessary services, managing errors, etc. We will discuss in details with the help of working examples.
  • Major Problem with this Architecture: The majore problem with this architecture is that, all the integrations bundle/jars deployed/worked on the same runtime (monolithic nature). For example, when you apply a configuration in the runtime, it will be applied to all your deployed bundles/jars applications.

What is Microservices (Fine-Grained) Architecture and Why it’s in trend?

  • It is also know as Fine-Grained architecture.
  • This architecture is kind of SOA architecture but with smaller and independent services.
  • This architecture, brings complexity to the architectural level, but main the advantage is that these microservices are all isolated and independent.

How MuleSoft achieving the Microservices Architecture?

  • Mulesoft is no longer just a middleware with SOA architecture.
  • We can use MuleSoft as microservices architecture with its integration as a service (SaaS) platform, Anypoint Platform.
  • Lets focus on below architecture in which we are spliting monolithic architecture into smaller and indepnedent services in layered architecture. For example see the below diagram of CRM application in Microservices architecture.
Microservices Architecture
  • Anypoint Runtime Fabric and Runtime Manager (integrated with Anypoint Platform), these applications can be deployed on Runtimes in instances on infrastructures managed by the client in AWS, Google Cloud, Azure and Virtual Machines etc.
  • We can use Cloudhub storage platform (integrated with the Anypoint Platform) for applications deployment so that they are automatically created and deployed as separate instances.

API-Led Connectivity (Layered Approach)

  • API-led connectivity is divided into three layers – Experience Layer, Process Layer, and System Layer.
  • The Experience Layer is the one that interacts with the client and has no implementation, only an exposed API that can be managed and secured.
  • The Process Layer interacts between the API exposed and the Systems Layer.
  • The System Layer connects to the necessary services (database, SAP, Salesforce, mail, e-commerce, etc.)

Application Overview

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.

Technology Stack

Anypoint Studio 7.4.2
Mule Server 4.2.2 EE
Java 1.8
Maven 3.5.0
HTTP Listener v1.5.11

Prerequisites (Setup MuleSoft (Mule 4), Maven 3.5 and JDK 1.8 on Windows OS)

We need Anypoint Studio, JDK and Maven for running below application on Mule 4 runtime or CloudHub instances.

Mulesoft download
maven 3.x binaries download
OpenJDK Windows x64 Download

Configure JDK, Maven and Mule Studio on Windows OS

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.

Create MuleSoft project in Mule Studio

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.

How to add Http Listener from Mule Palette

How to add Http Listener from Mule Palette

Add/Edit HTTP_Listener_config

Add/Edit HTTP_Listener_config
Add/Edit HTTP_Listener_config
Add/Edit HTTP_Listener_config

How to add and Set Payload in Mule message flow

For adding Payload we need to drag and drop Set Payload transformer to our Mule message flow

Mule Palette Set Payload Transformers

Complete Configuration XML

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.

How to run the application on runtime (Mule 4)

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 4 Runtime
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           *
*******************************************************************************************************

Hit HTTP Url On Browser/Postman

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

HTTP Listener - MuleSoft Rest API

Stop the Mule application in Anypoint Studio’s Console

To stop the application from running, click the red Terminate button in Studio’s Console.

Deploy to CloudHub

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.

CloudHub MuleSoft Application Deployment

It will ask for Anypoint’s credentials

How to add and Set Payload in Mule message flow

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.

Runtime version Worker size Workers Region Configurations in Mule CloudHub

Have a fantastic day. Thank you for reading 🙂