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
Please enter at least three characters to search
Refcards Trend Reports
Events Video Library
Refcards
Trend Reports

Events

View Events Video Library

Zones

Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks

Because the DevOps movement has redefined engineering responsibilities, SREs now have to become stewards of observability strategy.

Apache Cassandra combines the benefits of major NoSQL databases to support data management needs not covered by traditional RDBMS vendors.

The software you build is only as secure as the code that powers it. Learn how malicious code creeps into your software supply chain.

Generative AI has transformed nearly every industry. How can you leverage GenAI to improve your productivity and efficiency?

Related

  • DGS GraphQL and Spring Boot
  • Maven Dependency Scope Applied
  • A Maven Story
  • Integrate Cucumber in Playwright With Java

Trending

  • Build a Simple REST API Using Python Flask and SQLite (With Tests)
  • How To Introduce a New API Quickly Using Quarkus and ChatGPT
  • Code Reviews: Building an AI-Powered GitHub Integration
  • Agile’s Quarter-Century Crisis
  1. DZone
  2. Coding
  3. Java
  4. Deploy Mule 4 Application To Anypoint Runtime Fabric Using Maven Plugin

Deploy Mule 4 Application To Anypoint Runtime Fabric Using Maven Plugin

In this article, we are going to cover the following topics related to the deployment to Anypoint Runtime Fabric (RTF).

By 
Gary Liu user avatar
Gary Liu
DZone Core CORE ·
Jan. 30, 19 · Tutorial
Likes (3)
Comment
Save
Tweet
Share
24.5K Views

Join the DZone community and get the full member experience.

Join For Free

In the CI/CD process, it is very common to use a Mule Maven plugin to build and deploy an application to the Cloudhub, on-premise private cloud like AWS, Azure, Google Cloud, etc. Since Mule 4, a lot of changes related to the deployment has changed, particularly related to the Mule Runtime Fabric (RTF). Actually, RTF is a completely new infrastructure for Mule application deployment. I will cover more on that topic later. In this article, I am going to cover the following topics related to the deployment to Anypoint Runtime Fabric (RTF):

  1. Prepare pom.xml setup to deploy mule project to Anypoint RTF
  2. Encrypt password
  3. Troubleshooting

If everything works, at the end, we should be able to achieve the following goals:

  • deploy mule projects (assets) to Anypoint Exchange
  • deploy mule projects to Anypoint Runtime Fabric

In order for mule maven plugin to work, we need to change the following two files:

  • pom.xml
  • ./m2/settings.xml

The complete project for this article can be find at my github repository

In order to deploy mule applications using a mule maven plugin, we need to set the Anypoint credentials, which are the ones we use to login to anypoint portal (http://anypoint.mulesoft.com). The best way to do this is to add the server information in the .m2/settings.xml as the following:

<servers>
        <server>
              <id>ExchangeRepository</id>
              <username>gary_liu_client</username>
              <password>{5XLgXNDBGBIHa99xNAyJ6gL+ZxyUiyIJNHWu0H7Ctew=}</password>
        </server>
</servers>

The password is encrypted. To encrypt the password, we need to add another file namely: ~/.m2/settings-security.xml:

<settingssecurity>
  <master>{Vq5Aso1ZkO4HdJrUscJTZEii4BcFy+khGiGxDNVNgc4=}</master>
</settingssecurity>

The encrypt master password in the above is created by the following commands:

$ mvn --encrypt-master-password MasterPassword
{+4nnH6EW9HcHAHYBGnloFCAZZHSC4W3Xp9Zls0LvBqk=}

Once we encrypted the master password, we can encrypt the password to the anypoint portal as the following:

mvn --encrypt-password AnypointPortalPassword

For more details about the maven password encryption, you may refer to the following page: https://maven.apache.org/guides/mini/guide-encryption.html

pom.xml

<!--xml version="1.0" encoding="UTF-8" standalone="no"?-->
<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 http://maven.apache.org/maven-v4_0_0.xsd">
 <modelversion>4.0.0</modelversion>

 <groupid>fea874ca-11d9-4779-b1ce-90d49f738259</groupid>
 <artifactid>mule-maven-plugin</artifactid>
 <version>1.0.2</version>
 <packaging>mule-application</packaging>

 <name>mule-maven-plugin</name>

 <properties>
  <project.build.sourceencoding>UTF-8</project.build.sourceencoding>
  <project.reporting.outputencoding>UTF-8</project.reporting.outputencoding>
  <mule.maven.plugin.version>3.2.3</mule.maven.plugin.version>
  <anypoint.uri>https://anypoint.mulesoft.com</anypoint.uri>
  <anypoint.provider>MC</anypoint.provider>
  <deployment.environment>QA</deployment.environment>
<!--   <deployment.target>qa-azure-rtf</deployment.target> -->
  <app.runtime>4.1.4</app.runtime>
  <app.name>gary-deployment</app.name>
  <app.cores>100m</app.cores>
  <app.memory>500Mi</app.memory>
 </properties>

 <build>
  <plugins>
   <plugin>
    <groupid>org.mule.tools.maven</groupid>
    <artifactid>mule-maven-plugin</artifactid>
    <version>${mule.maven.plugin.version}</version>
    <extensions>true</extensions>
    <configuration>
     <runtimefabricdeployment>
      <uri>${anypoint.uri}</uri>
      <provider>${anypoint.provider}</provider>
      <environment>${deployment.environment}</environment>
      <target>${deployment.target}</target>
      <muleversion>${app.runtime}</muleversion>
      <server>ExchangeRepository</server>
      <applicationname>${app.name}</applicationname>
      <deploymentsettings>
       <replicationfactor>${deployment.replica}</replicationfactor>
       <cpureserved>${app.cores}</cpureserved>
       <memoryreserved>${app.memory}</memoryreserved>
      </deploymentsettings>
     </runtimefabricdeployment>
     <classifier>mule-application</classifier>
    </configuration>
   </plugin>

   <plugin>
    <groupid>org.codehaus.mojo</groupid>
    <artifactid>properties-maven-plugin</artifactid>
    <version>1.0.0</version>
    <executions>
     <execution>
      <phase>initialize</phase>
      <goals>
       <goal>read-project-properties</goal>
      </goals>
      <configuration>
       <files>
        <file>${maven.properties}</file>
       </files>
      </configuration>
     </execution>
    </executions>
   </plugin>
  </plugins>
 </build>

 <distributionmanagement>
  <repository>
   <id>ExchangeRepository</id>
   <name>Corporate Repository</name>
   <url>https://maven.anypoint.mulesoft.com/api/v1/organizations/${groupId}/maven</url>
   <layout>default</layout>
  </repository>
 </distributionmanagement>

 <dependencies>
           ......
 </dependencies>
        ......
</project>

The details are explained in the next section. But one item I must point out here: <groupId>fea874ca-11d9-4779-b1ce-90d49f738259</groupId>. The groupId is your Anypoint platform organization ID.

Explanations

The configuration in both pom.xml and settings.xml are pretty straightforward, however, a few items are worth explaining. First, what is the latest version of mule maven plugin? This can be found here. Currently, the latest version is 3.2.3.

Secondly, I use another plugin in addition to the mule maven plugin, namely, properties-maven-plugin. This plugin allows us to pass a property file to the pom.xml.

<plugin>
 <groupid>org.codehaus.mojo</groupid>
 <artifactid>properties-maven-plugin</artifactid>
 <version>1.0.0</version>
 <executions>
  <execution>
   <phase>initialize</phase>
   <goals>
    <goal>read-project-properties</goal>
   </goals>
   <configuration>
    <files>
     <file>${maven.properties}</file>
    </files>
   </configuration>
  </execution>
 </executions>
</plugin>

Note that in the configuration, we put ${maven.properties} variable. This allows as to pass the property file as:

mvn clean deploy -DmuleDeploy -Dmaven.properties=src/main/resources/mule.rtf.deploy.properties

Thirdly, note that in the mule maven plugin, I use <server>ExchangeRepository</server> as shown below. The ExchangeRespository is the server defined in the ~/.m2/settings.xml

<configuration>
 <runtimefabricdeployment>
  <uri>https://anypoint.mulesoft.com</uri>
  <provider>MC</provider>
  <environment>QA</environment>
  <target>qa-azure-rtf</target>
  <muleversion>4.1.4</muleversion>
  <server>ExchangeRepository</server>
  <applicationname>${app.name}</applicationname>
  <deploymentsettings>
   <replicationfactor>1</replicationfactor>
   <cpureserved>100m</cpureserved>
   <memoryreserved>500Mi</memoryreserved>
  </deploymentsettings>
 </runtimefabricdeployment>
 <classifier>mule-application</classifier>
</configuration>

The details for the parameters can be referred to here.

Publish Assets To Exchange

In order to deploy the mule application to RTF using the Mule Maven Plugin, we must publish the application (asset to Anypoint Exchange). To me, this extra step is unnecessary. To publish an artifact (asset) to the Anypoint Exchange, we run the following command:

mvn clean package deploy -Dmaven.properties=src/main/resources/mule.rtf.deploy.properties

After it completes the publishing, you can verify the result by the Anypoint Port using the following web address:
https://anypoint.mulesoft.com/exchange/{groupId}/{artifactId}
Here is my example:
https://anypoint.mulesoft.com/exchange/fea874ca-11d9-4779-b1ce-90d49f738259/mule-maven-plugin/

Deploy Application To RTF

Deployment to RTF can be slow and can sometimes take a very long time if it fails. I think the plugin should be improved by using asynchronous deployment instead of waiting and constantly checking with the runtime manager. The deployment to RTF can be done using the following command:

mvn clean package deploy -DmuleDeploy -Dmaven.properties=src/main/resources/mule.rtf.deploy.properties

Take Aways

The commands used in the process:

mvn --encrypt-master-password GaryLiu1234
mvn --encrypt-password GaryLiu1234
mvn clean package deploy-Dmaven.properties=src/main/resources/mule.rtf.deploy.properties
mvn clean package deploy -DmuleDeploy -Dmaven.properties=src/main/resources/mule.rtf.deploy.properties

Web address to check assets in the Anypoint Exchange in the Anypoint Portal:
https://anypoint.mulesoft.com/exchange/{groupId}/{artifactId}

Key Considerations using the Mule Maven Plugin in the CI/CD:

  • Make sure not to wait for the deployment to finish as it can take a very long time.
  • There are REST APIs you can use to check the deployment process. You should use the APIs to check the deploy.
  • At the moment, anypoint-cli is not working for RTF.
application Apache Maven

Published at DZone with permission of Gary Liu, DZone MVB. See the original article here.

Opinions expressed by DZone contributors are their own.

Related

  • DGS GraphQL and Spring Boot
  • Maven Dependency Scope Applied
  • A Maven Story
  • Integrate Cucumber in Playwright With Java

Partner Resources

×

Comments
Oops! Something Went Wrong

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

ABOUT US

  • About DZone
  • Support and feedback
  • Community research
  • Sitemap

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 100
  • Nashville, TN 37211
  • support@dzone.com

Let's be friends:

Likes
There are no likes...yet! 👀
Be the first to like this post!
It looks like you're not logged in.
Sign in to see who liked this post!