Domain Project and shared resource in Mulesoft

Priyanka Paul
5 min readJul 23, 2020

Problem statement :

I have defined a few global configurations such as default error handlers, shared properties, scheduler pools, Database connection and a few connector configurations which are common among all the applications deployed on mule on-premise ( example-Azure).

What if I need to update a few of the global properties and configurations, do I need to update all of the deployed applications one by one or is there any simple way to achieve this?

Solution:

Yes! Absolutely this can be achieved using a mule domain project.

To do so, first, create a Mule domain and define all your common global properties in this then refer to it from each of the applications. As a result, each of the applications now associated with the Mule domain can access shared resources configured in the domain. Any Mule application can be associated with only one domain at a time.

And this little optimization can help you save huge amounts of time.

Sharing resources allows multiple development teams to work in parallel using the same set of connector configurations. Expose multiple services within the domain through the same port. Share the connection to persistent storage. Share services between Mule applications through a well-defined interface. Ensure consistency between Mule applications upon any changes because the configuration is only set in one place.

Let’s understand the implementation process step by step :

  • Step 1: New Domain creation
  • Step 2: Shared Resources Configuration
  • Step 3: Associate any Mule Applications with New Domain
  • Step 4: Deploy with Shared Resources

New Domain creation

Mule-domain-config.xml will be created.

Adding the required modules in the domain project under Mule-domain-config.xml :

Shared Resources Configuration

Select the HTTP Connector and complete the configuration process:

Select the database config Connector and complete the configuration process

Similarly, define all the configurable parameters of your global element in the Global Element Properties window.

And your new Mule Domain is ready with shared resources ( http configuration, DB configuration) to associate with any mule application.

Associate any Mule Applications with New Domain

Associate a Mule App with a Domain Using Studio

Right click on project folder-> properties -> mule project -> select your custom domain name -> apply and Close

Now you can see the connector details in your mule palette and connector configuration from domain will be present.

Then I have written dwl code to retrieve the records from the database

%dw 2.0

output application/json

— -

{

Provider_information: payload,

Message: “Database connection loaded from the domain”

}

Associate a Mule App with a Domain from POM.XML

After completing these steps, Studio includes the domain in the pom.xml for your project, for example:

To associate a Mule app with a domain outside Studio, add the domain dependency to the pom.xml file as shown in the previous example.

<dependencies>

……..

<dependency>

<groupId>com.mycompany</groupId>

<artifactId>mymule4domain</artifactId>

<version>1.0.0-SNAPSHOT</version>

<classifier>mule-domain</classifier>

<scope>provided</scope>

</dependency>

…….

</dependencies>

Deploy with Shared Resources

By default, when you deploy either a Mule application associated with a domain or a domain associated with any Mule application, Anypoint Studio deploys both. You can change this default behaviour by changing the run configuration for the domain. You can also deploy a set of Mule applications in your workspace together, even if they don’t share the same domain.

Deploy from Anypoint Studio

The following steps describe how to deploy your domain project and the associated Mule applications from Studio:

Deploy Outside Anypoint Studio

The following steps describe how to deploy your domain project and the Mule applications outside Studio, to a standalone Mule runtime engine:

  1. In Studio, select File > Export.
  2. Select Mule > Anypoint Studio Project to Mule Deployable Archive (includes Studio metadata).
    This process creates a JAR file that you can deploy to a standalone Mule runtime engine.

Either you deploy the domain-project in local standalone runtime or you can create a server in cloud hub and deploy.

In Anypoint studio >Runtime Manger >Sandbox> Server> add server > copy the AMC command

Download mule mule-enterprise-standalone-4.3.0 and unzip it to any folder location.

Now go to the bin directory where you have extracted the mule-enterprise-standalone-4.3.0 runtime and open cmd.exe and paste that amc set up code and a server “mule-4-server” will be created in Anypoint runtime manager.

Now go to domains folder in the mule runtime directory and paste your domain jar

Example : C:\Users\ runtime\mule4\mule-enterprise-standalone-4.3.0\domains

Now deploy your application in anypoint runtime manager and select the deployment target as “mule-4-sever” and you are done!

Testing application with rest-client:

Thank you for reading …..!!!

--

--

Priyanka Paul

Hello Techies, I love to learn and grow. Currently working as mulesoft Developer @Salesforce . I have experience in both backend(java) and middleware (MuleSoft)