top of page

Cloudhub 2.0 Deployment using mule maven plugin (Part 1)

Updated: Apr 19, 2023

This is my first blog regarding Cloudhub 2.0 as everyone know Mulesoft has announced Cloudhub 2.0 available for users across 12 regions worldwide from mid of 2022.

As most of user's or clients are looking forward to take advantage of fully managed, containerized managed cloud service, where you can deploy and run MuleSoft applications which is cloudhub2.0, I will be walking you through mule deployment on cloudhub 2.0 using mule maven plugin.


In this blog I will provide steps or actions needed to deploy mule application on cloudhub 2.0 shared space using mule maven plugin and parameters will be explained.


  1. Lets create a simple mule application which returns welcome to cloudhub 2.0 world message on endpoint /api/demo


<?xml version="1.0" encoding="UTF-8"?>

<mule xmlns:ee="http://www.mulesoft.org/schema/mule/ee/core" 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://www.mulesoft.org/schema/mule/ee/core http://www.mulesoft.org/schema/mule/ee/core/current/mule-ee.xsd">
    <http:listener-config name="HTTP_Listener_config" doc:name="HTTP Listener config" doc:id="7489378d-da1f-4833-acf4-bf25cfff6e65" >
        <http:listener-connection host="0.0.0.0" port="8081" />
    </http:listener-config>
    <flow name="cloudhub2-demo-apiFlow" doc:id="74c23e26-c0f5-42ae-bef3-10ffee95de36" >
        <http:listener doc:name="Listener" doc:id="5ffba615-a968-4fd4-8398-59217426595e" config-ref="HTTP_Listener_config" path="/api/demo"/>
        <logger level="INFO" doc:name="Logger" doc:id="904f7d1a-45bf-431c-9792-750ee13212a5" message="Request Start Info Logger - #[message]"/>
        <ee:transform doc:name="Transform Message" doc:id="61fb7c30-b140-4d7e-8c39-26787e56568e" >
            <ee:message >
                <ee:set-payload ><![CDATA[%dw 2.0
output application/json
---
{
    "message": "welcome to cloudhub 2.0 world !!"
}]]></ee:set-payload>
            </ee:message>
        </ee:transform>
        <logger level="INFO" doc:name="Logger" doc:id="854782e1-1cdc-4b2e-8d85-3aa99a9c7698" message="Demo api logging end - #[message] and payload is #[payload]"/>
    </flow>
</mule>

2. In pom.xml we need to add mule maven plugin , make sure you are adding latest version or above Mule Maven Plugin (version 3.3.0) Warning - Mule Maven plugin versions 3.0.0, 3.1.0, 3.1.1, 3.1.2, 3.1.3, 3.1.4, 3.1.5, 3.1.6, 3.1.7, and 3.8.3 are deprecated.

Surely you will have additional parameters to be set on application e.g. encryption key,logging configuration scope or set publicUrl . These can be done using <deploymentSettings> tag <classifier> tag in this plugin is much important as it marks this as mule applications n can be found on exchange easily.

<plugin>
                <groupId>org.mule.tools.maven</groupId>
                <artifactId>mule-maven-plugin</artifactId>
                <version>3.7.1</version>
                <extensions>true</extensions>
                <configuration>
                    <cloudhub2Deployment>
                        <uri>https://anypoint.mulesoft.com</uri> <!-- provided by mulesoft no change -->
                        <provider>MC</provider> <!-- provided by mulesoft no change -->
                        <environment>${anypoint.environment}</environment> <!-- see this value into properties section of pom -->
                        <target>${anypoint.targetRegion}</target>
                        <muleVersion>${app.runtime}</muleVersion>
                        <server>anypoint-exchange-v3</server>
                        <applicationName>${project.artifactId}</applicationName>
                        <!-- <connectedAppClientId>YOURCLIENTID</connectedAppClientId> this can be used to publish api on exchange using connected app
                        <connectedAppClientSecret>YOURCLIENTSECRET</connectedAppClientSecret>  in this template we will use it from .m2 config settings.xml
                        <connectedAppGrantType>client_credentials</connectedAppGrantType> -->
                        <replicas>${app.replicas}</replicas>
                        <version>${project.version}</version>
                        <vCores>${app.vcores}</vCores>
                    </cloudhub2Deployment>
                    <classifier>mule-application</classifier>
                </configuration>
            </plugin>

** ${key} - value for this fields is picked from properties section of pom.xml or you can pass those on argument as well

3. For shared space below are values available for target field (this is not mentioned on mulesoft documentation yet, for which I will raise a PR to get this added on documentation)

So set value as per region where you would to deploy application

Cloudhub-US-East-1 (US East, N. Virginia)

Cloudhub-US-East-2 (default;US East, Ohio)

Cloudhub-US-West-1 (US West, N. California)

Cloudhub-US-West-2 (US West, Oregon)

Cloudhub-CA-Central-1 (Canada, Central)

Cloudhub-SA-East-1 (South America, São Paulo)

Cloudhub-EU-West-1 (EU, Ireland)

Cloudhub-EU-Central-1 (EU, Frankfurt)

Cloudhub-EU-West-2 (EU, London)

Cloudhub-AP-SouthEast-1 (Asia Pacific, Singapore)

Cloudhub-AP-SouthEast-2 (Asia Pacific, Sydney)

Cloudhub-AP-NorthEast-1 (Asia Pacific, Tokyo)


4. The Mule Maven Facade API (v3) is added as a repository in the distribution management section of your project’s POM file. For example:

replace or set value for your organization field


    <distributionManagement>
        <repository>
            <id>anypoint-exchange-v3</id>
            <name>Corporate Repository</name>
         <url>https://maven.anypoint.mulesoft.com/api/v3/organizations/${anypoint.organizationId}/maven</url>
            <layout>default</layout>
        </repository>
    </distributionManagement>    

5. There are 3 options to authorise maven plugin to publish on exchange and deploy app on cloudhub 2.0

A. basic cloudhub 2.0 username and password

B. Authorization Token C.Connected Apps

In this scenario, we will using connected apps to authorise mule maven plugin to publish asset on exchange and then deploy on cloudhub 2.0

For this lets create connected app on Anypoint platform -> go to Access Management ->

click on connected app -> create new app

Provide access on exchange, runtime manager and design centre to this application.

save it and you can copy client id and client secret for this application.


6. Set this connected app details on .m2/config/settings.xml file under server tab

make sure server id on settings.xml file is same as mentioned on pom.xml server field of deployment part of mule maven plugin. In this case it is anypoint-exchange-v3


settings.xml should be as below


<?xml version="1.0" encoding="UTF-8"?>

<settings

xmlns="http://maven.apache.org/SETTINGS/1.0.0"

xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"

xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0 http://maven.apache.org/xsd/settings-1.0.0.xsd">

<servers>

<!-- MuleSoft Nexus EE Repository -->

<server>

<id>anypoint-exchange-v3</id>

<username>~~~Client~~~</username>

<password>clientIdinplaintext~?~clientSecretinplaintext</password>

</server>

</servers>

</settings>



7. In Repositories, make sure maven anypoint v3 repo is mentioned as below

<repository>
            <id>anypoint-exchange-v3</id>
            <name>Anypoint Exchange</name>
            <url>https://maven.anypoint.mulesoft.com/api/v3/maven</url>
            <layout>default</layout>
        </repository>

8. Attaching whole pom.xml for reference



<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <groupId>9b33ea8c-cd7c-414d-8d2c-bdc3ce408cfd</groupId>
    <artifactId>cloudhub2-demo-api</artifactId>
    <version>1.0.0-SNAPSHOT</version>  <!-- this version will drive asset version to be development state or stable state -->
    <packaging>mule-application</packaging>
    <description>This is mule demo api for cloudhub 2.0 deployment </description>
    <name>cloudhub2-demo-api</name>

    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
        <anypoint.organizationId>9b33ea8c-cd7c-414d-8d2c-bdc3ce408cfd</anypoint.organizationId>
        <anypoint.environment>Sandbox</anypoint.environment>
        <anypoint.targetRegion>Cloudhub-US-East-2</anypoint.targetRegion>
        <app.runtime>4.4.0-20220221</app.runtime>
        <app.replicas>1</app.replicas>
        <app.vcores>0.5</app.vcores>
    </properties>

    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-clean-plugin</artifactId>
                <version>3.0.0</version>
            </plugin>
            <plugin>
                <groupId>org.mule.tools.maven</groupId>
                <artifactId>mule-maven-plugin</artifactId>
                <version>3.7.1</version>
                <extensions>true</extensions>
                <configuration>
                    <cloudhub2Deployment>
                        <uri>https://anypoint.mulesoft.com</uri>
                        <provider>MC</provider>
                        <environment>${anypoint.environment}</environment>
                        <target>${anypoint.targetRegion}</target>
                        <muleVersion>${app.runtime}</muleVersion>
                        <server>anypoint-exchange-v3</server>
                        <applicationName>${project.artifactId}</applicationName>
                        <!-- <connectedAppClientId>YOURCLIENTID</connectedAppClientId> this can be used to publish api on exchange using connected app
                        <connectedAppClientSecret>YOURCLIENTSECRET</connectedAppClientSecret>  in this template we will use it from .m2 config settings.xml
                        <connectedAppGrantType>client_credentials</connectedAppGrantType> -->
                        <replicas>${app.replicas}</replicas>
                        <version>${project.version}</version>
                        <vCores>${app.vcores}</vCores>
                    </cloudhub2Deployment>
                    <classifier>mule-application</classifier>
                </configuration>
            </plugin>
        </plugins>
    </build>
    <distributionManagement>
        <repository>
            <id>anypoint-exchange-v3</id>
            <name>Corporate Repository</name>
            <url>https://maven.anypoint.mulesoft.com/api/v3/organizations/${anypoint.organizationId}/maven</url>
            <layout>default</layout>
        </repository>
    </distributionManagement>
    <dependencies>
        <dependency>
            <groupId>org.mule.connectors</groupId>
            <artifactId>mule-http-connector</artifactId>
            <version>1.6.0</version>
            <classifier>mule-plugin</classifier>
        </dependency>
        <dependency>
            <groupId>org.mule.connectors</groupId>
            <artifactId>mule-sockets-connector</artifactId>
            <version>1.2.2</version>
            <classifier>mule-plugin</classifier>
        </dependency>
    </dependencies>

    <repositories>
        <repository>
            <id>anypoint-exchange-v3</id>
            <name>Anypoint Exchange</name>
            <url>https://maven.anypoint.mulesoft.com/api/v3/maven</url>
            <layout>default</layout>
        </repository>
        <repository>
            <id>mulesoft-releases</id>
            <name>MuleSoft Releases Repository</name>
            <url>https://repository.mulesoft.org/releases/</url>
            <layout>default</layout>
        </repository>
    </repositories>

    <pluginRepositories>
        <pluginRepository>
            <id>mulesoft-releases</id>
            <name>MuleSoft Releases Repository</name>
            <layout>default</layout>
            <url>https://repository.mulesoft.org/releases/</url>
            <snapshots>
                <enabled>false</enabled>
            </snapshots>
        </pluginRepository>
        <pluginRepository>
            <id>mule-public</id>
            <url>https://repository.mulesoft.org/nexus/content/repositories/releases</url>
        </pluginRepository>
    </pluginRepositories>

</project>

9. Lets open command prompt where this project has been saved on local drive

#How to Build > mvn clean package -> build project and create jar file > mvn clean install -> add jar file on .m2 repository local cache #Publish asset to exchange (mandatory step for cloudhub2.0 deployment) > mvn clean deploy once this steps is completed, you will be able to see your application on exchange using below url https://anypoint.mulesoft.com/exchange/?type=app&show=all be default you will not be able to see your application on exchange so try above url. #How to Deploy to Cloudhub >mvn clean deploy -DmuleDeploy

Once Application is deployed, you can click public URL and add endpoint /api/demo to see result as below



Code has been published on github repo at below location.


If you like this blog then please like and share with your friends. If any question or issue, please comment here


References -


bottom of page