Multiple layers of API
We all know about API led approach in MuleSoft, where we work with multiple layers of API, mostly 3 layers e.g. experience layer, process layer, and system layer. In a smaller scale project, you might not come across any problems but at enterprise applications, you might need to work with two or more layers at a time. Let’s assume, you are working with process layer which connects to system layer, so while you are working with process layer, you might need to run the system layer as well to successfully run/debug the process layer. Because if your system layer is not available/running while you’re running/debugging process layer, it will throw you an error like below when it would try to connect to the system layer.
“Error sending request to https://localhost:8081/somepath/”
There are multiple ways you can resolve this error:
One way is to import system and process layers projects into same workspace and then configure Run Configurations/Debug Configurations to run and/or debug both applications simultaneously.
Though it’s good way to go but there are a few drawbacks of doing this:
- Whenever you want to stop one application it will stop other application as well. That means, you might want to stop running process layer and do some modification but in the process it will also stop the system layer as well. Every time you want to run or debug the process layer, system layer will also start running which is not necessary and can be time consuming in case of large scale applications. What if you want to keep system layer running while you constantly working on process layer?
- You can not change the way of running of each layer projects. That means, if you start your process layer in debug mode, it will also kick off system layer in debug mode. But what if you want to run process layer application in debug mode because you want to debug through the flows but you don’t want to debug system layer?
To address these drawbacks, Mule Runtime Standalone Engine comes to rescue. Let’s see how we can achieve this:
- Download and install JDK 1.8.xxx from https://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-2133151.html . Please note JDK 1.8 with any minor version is recommended. Do not install JRE or JDK with different major version other than 1.
- Download Mule 4 Standalone Runtime from https://www.mulesoft.com/lp/dl/mule-esb-enterprise
- Extract Mule 4 Runtime in root folder. I will demonstrate in terms of Windows OS. It’s recommended to put Mule 4 Runtime in any drives with less or no nested folder hierarchy. This is because Windows has character limitations in folder/file path which might be the issue while extracting contents from compressed folder.
- After extracting, navigate inside Mule runtime folder and then navigate to /bin folder. Run command prompt/terminal window from that location.
- Execute following command to run Mule Runtime in your machine.
Windows: mule.bat (or mule)
Unix: sudo ./mule
This will kick off Mule Runtime Server in your machine. Wait for it to start.
- Once server is started, navigate to the Mule Runtime installation location and look for /apps folder.
- Put your application deployable jar file inside that folder. In our case we want to run system layer in Mule Runtime. Let’s try to do that and have a look at the terminal window, you’ll see that your application will be deployed in some time.
Please note that if your application belongs to different domain other than default, then you need to deploy your domain projects first before you can deploy your application otherwise it will throw error. To deploy your domain projects, navigate to the /domains folder and paste your domain project jar. It will kick off domain project and then you can follow Step 7 to deploy your application.
Now, your system layer application will run inside Mule Runtime while you can run or debug your process layer from Anypoint Studio. You don’t have to run system layer every time.
To see logs of applications running in your Mule Runtime, navigate to /logs folder inside your Mule Runtime installation directory, then you can see a log file has been created with same name as your application name.
Hope these tips and tricks help you in achieving a seamless approach while working with multiple layers of API. Keep exploring, keep learning and keep sharing!
About Incepta Solutions
At Incepta Solutions, our team of #InceptaInnovators is passionate about developing the bridge between people and operations, as we create stories that we can all be proud of. Since our inception in 2010, we are recognized as trusted experts in providing digital services to global businesses. We are proud to be named one of the top 5 Information Technology companies in Canada on the Growth List 2020 (published by Canadian Business and MacLeans). In addition, we are humbled to be recently certified as a Great Place to Work.
Our full suite of digital services includes:
Cybersecurity | Integration | Digital Transformation
Data Management | Cloud Strategy | Customer 360
At Incepta Solutions, we provide business solutions that solve challenges and enable future growth and success for all of our clients. We leverage industry-leading technologies to provide innovative solutions that are robust, of premier quality, and cost-effective.
In our growth journey, our goal is to become a global leader in digital transformation and enterprise solutions. We enable businesses all over the world to solve complex and critical integration challenges. As #InceptaInnovators, we hope to look back at these times on how we have helped global brands and enterprises achieve success. Our driving force is that one day, we are able to reflect on our shared journey and be proud of the stories we have created together.
Incepta Solutions | Powered by innovation, driven by results