Running Mule CE Embedded with Spring Boot

In recent years there has been a surge in the idea of microservices. Although this term is vague in nature there are some ideas on how to deploy and run applications with “microservices” in mind.

Spring has come to the forefront of the microservice architecture with its “opinionated view of building production-ready Spring applications”.

While Spring Boot provides several “starter” configurations for most application needs, Spring will at times have to integrate or take a back seat to other systems.

By design, that is the beauty of Spring…it can utilized as a top level container or nicely integrated into your current solution. for more skills Mulesoft Certification

Mule CE is an open source integration tool. Mule CE applications are normally run inside a Mule runtime. With mule-spring-boot-starter, you can run Mule CE embedded in a Spring Boot application.

This allows Mule developers to quickly prototype and/or deploy Mule applications without having to download Mule runtime, create a Maven artifact, and push the artifact to the Mule runtime.

This project will allow developers to build and run the Mule application in much the same manner as other Spring Boot applications.

Add Maven Dependency:

<dependency>
    <groupId>net.taptech</groupId>
    <artifactId>mule-spring-boot-starter</artifactId>
    <version>1.0.0</version>
</dependency>

Add Repositories:

<repositories>
    <repository>
        <id>Central</id>
        <name>Central</name>
        <url>http://repo1.maven.org/maven2/</url>
        <layout>default</layout>
    </repository>
    <repository>
        <id>mulesoft-releases</id>
        <name>MuleSoft Repository</name>
        <url>http://repository.mulesoft.org/releases/</url>
        <layout>default</layout>
    </repository>
    <repository>
        <id>mulesoft-snapshots</id>
        <name>MuleSoft Snapshot Repository</name>
        <url>http://repository.mulesoft.org/snapshots/</url>
        <layout>default</layout>
    </repository>
    <repository>
        <id>spring-milestones</id>
        <name>Spring Milestones Repository</name>
        <url>http://repo.spring.io/milestone</url>
        <layout>default</layout>
    </repository>
    <repository>
        <id>spock-snapshots</id>
        <url>https://oss.sonatype.org/content/repositories/snapshots/</url>
        <snapshots>
            <enabled>true</enabled>
        </snapshots>
    </repository>
</repositories>

Add Mule Modules and Dependencies as Needed:

the HTTP connector is used so that a jar file is needed for the XML schema and corresponding Java code to support the HTTP connector.

<dependency>
    <groupId>org.mule.transports</groupId>
    <artifactId>mule-transport-http</artifactId>
    <version>${mule.version}</version>
</dependency>

Create a Mule Config File:

Make sure this file is in the artifact classpath. Create an application property called
 mule.config.files. Add a comma separated list of mule config files.

mule.config.files=mule-config.xml

Here’s an example mule-config.xml file: For additional skills Mulesoft Online Training

<?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_Configuration" host="0.0.0.0" port="8081" doc:name="HTTP Listener Configuration" />
    <flow name="mule-demo-filesFlow">
        <logger level="INFO" doc:name="Logger" category="net.taptech" message="It works!!!!" />
        <set-payload value="testing" doc:name="Set Payload" />
    </flow>
    <flow name="mule-demo-filesFlow1">
        <http:listener config-ref="HTTP_Listener_Configuration" path="/test" doc:name="HTTP" />
        <flow-ref name="mule-demo-filesFlow" doc:name="mule-demo-filesFlow" />
    </flow>
</mule>

Add Annotation to Your Spring Boot Application Entry Point:

@EnableMuleConfiguration

@EnableMuleConfiguration
@SpringBootApplication
public class DemoMuleSpringBootApplication {
 private static final Logger logger = LoggerFactory.getLogger(DemoMuleSpringBootApplication.class);
 @Autowired
 private ApplicationContext context;
 public static void main(String...args) {
  logger.info("Starting SpringApplication...");
  SpringApplication app = new SpringApplication(DemoMuleSpringBootApplication.class);
  app.setBannerMode(Banner.Mode.CONSOLE);
  app.setWebEnvironment(false);
  app.run();
  logger.info("SpringApplication has started...");
 }
}

To get in-depth knowledge, enroll for a live free demo on Mulesoft Training

Leave a comment

Design a site like this with WordPress.com
Get started