DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Refcards Trend Reports
Events Video Library
Refcards
Trend Reports

Events

View Events Video Library

Related

  • A Practical Guide to Creating a Spring Modulith Project
  • Distributed Tracing System (Spring Cloud Sleuth + OpenZipkin)
  • Java, Spring Boot, and MongoDB: Performance Analysis and Improvements
  • Spring Boot Secured By Let's Encrypt

Trending

  • The AI Autonomy Spectrum: 7 Architecture Patterns for Intelligent Applications
  • Deployment Lessons You Only Learn the Hard Way
  • If You Can Survive a Toddler, You Can Ship LLMs in Production
  • Getting Started With Agentic Workflows in Java and Quarkus
  1. DZone
  2. Coding
  3. Frameworks
  4. Embed Mule 4 Runtime Into a Spring Boot Application

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.

By 
Manuel Núñez user avatar
Manuel Núñez
·
Feb. 01, 21 · Tutorial
Likes (5)
Comment
Save
Tweet
Share
13.7K Views

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 Goal

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.

article image

Your Home Cooked "Spring Boot Mule 4 Runtime"

The Ingredients

  • JDK 8
  • Maven 3.5+
  • Spring Boot 2.1.0+
  • Mule Runtime 4.2.1-4.3.0
  • A pom.xml file
  • A main Class

The pom.xml

XML
 


x
 
1
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
2
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3
  xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
4
  <modelVersion>4.0.0</modelVersion>
5
  <groupId>org.hawkore.springframework.boot</groupId>
6
  <artifactId>spring-boot-mule4-runtime-ce</artifactId>
7
  <version>4.2.2</version>
8
  <packaging>jar</packaging>
9

          
10
  <properties>
11
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
12
    <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
13
    <maven.compiler.source>1.8</maven.compiler.source>
14
    <maven.compiler.target>1.8</maven.compiler.target>
15
    <maven-compiler-plugin.version>3.7.0</maven-compiler-plugin.version>
16
    <maven.deploy.skip>true</maven.deploy.skip>
17
    <maven.install.skip>true</maven.install.skip>
18

          
19
    <!-- Spring boot starter for Mule -->
20
    <mule4-spring-boot-starter.version>2.0.0</mule4-spring-boot-starter.version>
21

          
22
    <!-- spring-boot-admin-client to register at spring boot admin server-->
23
    <spring-boot-admin-client.version>2.1.6</spring-boot-admin-client.version>
24

          
25
    <!-- Should match with Mule's one to avoid incompatibilities -->
26
    <spring-boot.version>2.1.6.RELEASE</spring-boot.version>
27
    <projectReactorVersion>3.2.12.RELEASE</projectReactorVersion>
28
    <projectReactorExtraVersion>3.1.6.RELEASE</projectReactorExtraVersion>
29

          
30
    <muleProductExt></muleProductExt>
31
  </properties>
32

          
33
  <build>
34
    <plugins>
35
      <plugin>
36
        <groupId>org.springframework.boot</groupId>
37
        <artifactId>spring-boot-maven-plugin</artifactId>
38
        <configuration>
39
          <executable>true</executable>
40
        </configuration>
41
        <executions>
42
          <execution>
43
            <goals>
44
              <goal>repackage</goal>
45
              <goal>build-info</goal>
46
            </goals>
47
          </execution>
48
        </executions>
49
      </plugin>
50
      <plugin>
51
        <groupId>org.apache.maven.plugins</groupId>
52
        <artifactId>maven-compiler-plugin</artifactId>
53
        <configuration>
54
          <source>${maven.compiler.source}</source>
55
          <target>${maven.compiler.target}</target>
56
          <encoding>${project.build.sourceEncoding}</encoding>
57
        </configuration>
58
      </plugin>
59
    </plugins>
60
  </build>
61

          
62
  <dependencyManagement>
63
    <dependencies>
64
      <dependency>
65
        <groupId>org.springframework.boot</groupId>
66
        <artifactId>spring-boot-dependencies</artifactId>
67
        <version>${spring-boot.version}</version>
68
        <type>pom</type>
69
        <scope>import</scope>
70
      </dependency>
71
    </dependencies>
72
  </dependencyManagement>
73

          
74
  <dependencies>
75

          
76
    <!-- Optional Spring Boot Web for Mule deployment services and remote management -->
77
    <dependency>
78
      <groupId>org.springframework.boot</groupId>
79
      <artifactId>spring-boot-starter-web</artifactId>
80
      <exclusions>
81
        <exclusion>
82
          <groupId>org.springframework.boot</groupId>
83
          <artifactId>spring-boot-starter-tomcat</artifactId>
84
        </exclusion>
85
      </exclusions>
86
    </dependency>
87

          
88
    <dependency>
89
      <groupId>org.springframework.boot</groupId>
90
      <artifactId>spring-boot-starter-undertow</artifactId>
91
    </dependency>
92

          
93
    <!-- Optional for remote management actuator + client -->
94
    <dependency>
95
      <groupId>org.springframework.boot</groupId>
96
      <artifactId>spring-boot-starter-actuator</artifactId>
97
    </dependency>
98

          
99
    <dependency>
100
      <groupId>de.codecentric</groupId>
101
      <artifactId>spring-boot-admin-starter-client</artifactId>
102
      <version>${spring-boot-admin-client.version}</version>
103
    </dependency>
104

          
105
    <!-- Spring boot starter for Mule 4 Runtime CE -->
106
    <dependency>
107
      <groupId>org.hawkore.springframework.boot</groupId>
108
      <artifactId>mule4-spring-boot-starter-ce</artifactId>
109
      <version>${mule4-spring-boot-starter.version}</version>
110
    </dependency>
111

          
112
    <!-- Required by Mule's APIKit -->
113
    <dependency>
114
      <groupId>io.projectreactor</groupId>
115
      <artifactId>reactor-core</artifactId>
116
      <version>${projectReactorVersion}</version>
117
    </dependency>
118

          
119
    <dependency>
120
      <groupId>io.projectreactor.addons</groupId>
121
      <artifactId>reactor-extra</artifactId>
122
      <version>${projectReactorExtraVersion}</version>
123
      <exclusions>
124
        <exclusion>
125
          <groupId>io.projectreactor</groupId>
126
          <artifactId>reactor-core</artifactId>
127
        </exclusion>
128
      </exclusions>
129
    </dependency>
130

          
131
    <!-- Add here more dependencies: Mule patches, etc... -->
132

          
133
  </dependencies>
134

          
135
  <repositories>
136
    <repository>
137
      <id>central</id>
138
      <name>Central Repository</name>
139
      <url>https://repo.maven.apache.org/maven2</url>
140
    </repository>
141
    <repository>
142
      <id>mulesoft-releases</id>
143
      <name>MuleSoft Releases Repository</name>
144
      <url>https://repository.mulesoft.org/releases/</url>
145
      <layout>default</layout>
146
    </repository>
147
  </repositories>
148

          
149
</project>

The main Class

Java
 


x
18
 
1
package org.hawkore.springframework.mule;
2

          
3

          
4
import org.hawkore.springframework.boot.mule.config.EnableSpringMuleRuntimeDeploymentServices;
5
import org.springframework.boot.Banner.Mode;
6
import org.springframework.boot.SpringApplication;
7
import org.springframework.boot.autoconfigure.SpringBootApplication;
8

          
9

          
10
@EnableSpringMuleRuntimeDeploymentServices
11
@SpringBootApplication
12
public class SpringBootEmbeddedMuleRuntime {
13

          
14
    public static void main(String[] args) {
15
        SpringApplication app = new SpringApplication(SpringBootEmbeddedMuleRuntime.class);
16
        app.setBannerMode(Mode.OFF);
17
        app.run(args);
18
    }
19

          
20
}

The Mule 4 Runtime Version

Build it with the Mule 4 Runtime BOM version you want, for example 4.2.2-hf5:

Shell
 




xxxxxxxxxx
1


 
1
mvn clean package -Dmule.bom.version=4.2.2-hf5


Check available Mule Runtime Kernel BOM versions at MuleSoft's public Maven repository.

Easy Peasy...

Just run your Mule applications using your home cooked "Spring Boot Mule 4 Runtime":

Shell
 




x


 
1
java -Dmule.base=/opt/mule -Dmule.apps=file:/opt/muleapps/sample-app-1.0.0-mule-application.jar -jar target/spring-boot-mule4-runtime-ce-4.2.2.jar




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:

Prefix Example Explanation
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.


Shell
 




xxxxxxxxxx
1


 
1
java -Dmule.base=/opt/mule -Dmule.apps=https://my.nexus.server.com/repositories/internal/org/mule/apps/sample-app-1.0.0-mule-application.jar?access_token=1234 -jar target/spring-boot-mule4-runtime-ce-4.2.2.jar


See more examples at GitHub.

Spring Framework Spring Boot application

Opinions expressed by DZone contributors are their own.

Related

  • A Practical Guide to Creating a Spring Modulith Project
  • Distributed Tracing System (Spring Cloud Sleuth + OpenZipkin)
  • Java, Spring Boot, and MongoDB: Performance Analysis and Improvements
  • Spring Boot Secured By Let's Encrypt

Partner Resources

×

Comments

The likes didn't load as expected. Please refresh the page and try again.

  • RSS
  • X
  • Facebook

ABOUT US

  • About DZone
  • Support and feedback
  • Community research

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Core Program
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 3343 Perimeter Hill Drive
  • Suite 215
  • Nashville, TN 37211
  • [email protected]

Let's be friends:

  • RSS
  • X
  • Facebook