Automated deployment with Mule Management Console and Maven

3 Jan

In my opinion a deployment of any application should be as automated as possible to avoid errors due to manual mistakes. This is no different with a Mule ESB application. If you are using the Enterprise Edition of the Mule ESB you also have the ability to make use of the Mule Management Console (MMC). This instrument makes the governance of the deployment of your Mule applications into different environments easier and therefore the whole deployment cycle less error-prone.
One item that I am missing in the MMC is to automatically add a new version of your Mule Application into the MMC. You can upload your Mule applications manually with MuleStudio (which enforces you to use MuleStudio of which I am not a big fan) or by uploading it by using the MMC itself being also manually.
Luckily there is one escape for this which is the REST API that is available for the MMC. Combined with a Maven plugin you can have your Mule application uploaded to the MMC and deployed automatically. Although Mulesoft doesn’t supply this plugin themselves I found an open source version here. I used this as my starting point and added a few enhancements that are useful (at least in my situation). The sources can be found here.
The situation I added is the following:
In case I upload a ‘SNAPSHOT’ version of an application, the existing application is removed from the MMC repository and the new SNAPSHOT version is added. In case of a non-snapshot version only a new version is allowed, an error message is received otherwise. Deployments that are already using the SNAPSHOT version will be redeployed with the new version. As a rule a SNAPSHOT version should only be deployed to the Test environment and never make it to Acceptance or Production.
When you have added the plugin to your Maven repository you can use it in your Mule project by adding the following configuration to your pom:

...
<build>
  <plugins> 
    <plugin>
      <groupId>org.mule.tools</groupId>
      <artifactId>mule-mmc-rest-plugin</artifactId>
      <version>1.1.1-SNAPSHOT</version>
      <executions>
        <execution>
          <id>mule-deploy</id>
          <phase>install</phase>
          <goals>
            <goal>deploy</goal>
          </goals>
          <configuration>
            <muleApiUrl>${muleApiUrl}</muleApiUrl>
            <name>${artifactId}</name>
            <username>admin</username>
            <password>admin</password>
            <appDirectory>${project.basedir}/src/main/app</appDirectory>
            <finalName>${artifactId}-${version}</finalName>
            <version>${version}</version>
            <serverGroup>Test</serverGroup>
          </configuration>
        </execution>
      </executions>
    </plugin>
    ...
  </plugins>
</build>
...

In my parent pom I have defined the property 'muleApiUrl' as:

  ...
  <properties>
    <muleApiUrl>http://mmc-host:8080/mmc/api</muleApiUrl>
  <properties>
  ...

The ServerGroup 'Test' refers to my Test Server in the MMC:
mmc-screenshot
So every time I run 'mvn install' the Mule application is added to the repository of MMC and deployed to the Test environment. From the MMC it can then be promoted to Acceptance or Production.

2 Responses to “Automated deployment with Mule Management Console and Maven”

  1. krizsan 09/01/2014 at 06:17 #

    Thanks! I have been thinking about using the REST interface of the MMC for a while but haven’t quite found the time.

Trackbacks/Pingbacks

  1. Bookmarks #2 | Adao Feliz - Software Craftsman - Blog - 09/01/2014

    […] Automated deployment with Mule and Maven - Continuous Delivery is trending up as a design practice for software delivery. Pascal Alma shows how to integrate Mule Management Console (MMC) and Maven, enabling a automatic deployment of any application avoiding errors that could be caused by manual mistakes. There are other options as Rundeck but Mule isn’t bad at all. […]

Comments are closed.

Follow

Get every new post delivered to your Inbox.

Join 93 other followers

%d bloggers like this: