Embed Mule 4 Runtime Into a Spring Boot Application
A developer gives a tutorial on creating a Spring Boot application that takes advantage of Mule to establish a consistent and sustainable application.
Join the DZone community and get the full member experience.Join For Free
Intro to Mule
One of Mule’s main capabilities is that it allows you to forget about point-to-point integrations, which can become a real headache as they grow in complexity.
Mule is a ESB (Enterprise Service Bus) messaging framework, scalable and distributable, that can orchestrate interactions with services and applications using different transport and messaging technologies.
Relying on Mule’s reusability and connectivity allows you to establish a much more consistent and sustainable application network, so that future integrations can reuse previously created components and integrate them into the network in an increasingly dynamic way.
With this in mind, MuleSoft proposes the use of an API-led Connectivity architecture when designing the model of integrations to be managed with Mule ESB.
The main goal of this article is to join Mule's productivity with the Spring Boot ecosystem. To achieve this we are going to use Spring Boot Starter for Mule 4, an open-source library licensed under the Apache License 2.0.
This will allow you to build highly productive and easily scalable systems with very interesting features:
- Mule Runtime monitoring with Spring Boot Admin:
- Easy loglevel management.
- Follow and download logfile.
- JVM and memory metrics.
- Interact with JMX-beans.
- Show health status.
- Manage Mule artifacts (applications/domains), exposing Mule deployment services through Spring Boot REST controllers, as a stand-alone instance.
- Easy deployment of Mule applications as microservices on Kubernetes or another container management platform.
- Deploy Mule artifacts stored in an external repository.
- Improve CI/CD, building Docker images within seconds containing the latest Mule Runtime version and deploying your Mule applications on a container management platform, for example Kubernetes, to test integrations before deploying them to production.
Your Home Cooked "Spring Boot Mule 4 Runtime"
- JDK 8
- Spring Boot
- Mule Runtime
- A pom.xml file
The main Class
The Mule 4 Runtime Version
Build it with the Mule 4 Runtime BOM version you want, for example 4.2.2-hf5:
Check available Mule Runtime Kernel BOM versions at MuleSoft's public Maven repository.
Just run your Mule applications using your home cooked "Spring Boot Mule 4 Runtime":
What if Your Mule Applications Are Located in an External Repository?
Don't worry, you can still load them. Mule applications and Mule domains are loaded using Spring's ResourceLoader, so you can provide a well-known URL format:
|classpath:||classpath:com/myapp.jar||Loaded from the classpath.|
|file:||file:/opt/shared/myapp.jar||Loaded as a URL, from the filesystem.|
|http(s):||http://myserver/myapp.jar||Loaded as a URL.|
See more examples at GitHub.
Opinions expressed by DZone contributors are their own.