Why Mule Domain Project?
A Mule Domain project is used to configure shared resources so these shared resources can be accessed from different Mule projects associated with this domain project. Once we create and deploy a domain project, a domain is created with the project name, so you can configure this domain in your application either by using mule-deploy.properties file or by using mule-project.xml so that all the resources configured in it can be accessed.
What Are Shared Resources?
Mule supports the ability to define selected connectors as common resources and expose them to all applications deployed under the same domain. These resources are known as shared resources; to host these, you must create a Mule Domain Project and then reference it on each of the projects that are meant to use the elements in it. Once defined, any Mule application associated with a particular domain can access resources in this file. Note that Mule applications can be associated with only one domain at a time.
Shared resources allow multiple development teams to work in parallel using the same set of reusable connectors. Defining these connectors as shared resources at the domain level allows the team to:
- Expose multiple services within the domain through the same port,
- Share the connection to persistent storage,
- Share services between applications through a well-defined interface,
- Ensure consistency between applications upon any changes, as the configuration is only set in one place.
This document assumes that you are using Anypoint Studio with Mule runtime 3.6 or newer, or that you are building your applications outside Studio and deploying them to Mule Standalone 3.5.0 runtime or newer.
Creating a Mule Domain Project
Open Anypoint Studio, and Click on "File" ===> click on "New" ===> select and click on "Mule Domain Project" and then enter your domain project name as shown in the attached screenshot.
Once you have created this domain project, the structure of the project looks like this:
As you have created the domain project with the name "first-mule-domain-project," you can now configure "Shared Resources" in this project. I'm going to create a "Http Listener" Shared Resource in this project so that it can be accessed from my other Mule projects.
To create a Shared Resource in our domain project, we need to configure (or copy and paste) the corresponding resource's schemaLocation and its namespaces in our domain project. As I'm going to configure the HTTP Listener as a Shared Resource, I need to configure the below schemaLocation and namespace in my domain project's "mule-domain-config.xml," file as shown in the below screenshot.
For namespace use:
For schemaLocation use:
As you have created a configured namespace and schemaLocation, now you will be able to configure the below Http Listen in your domain project:
<http:listener-config name="HTTP_Listener_Configuration" host="0.0.0.0" port="9876" doc:name="HTTP Listener Configuration"/>
This is an HTTP listener; you can refer to this from any of your Mule projects associated with this domain (first-mule-domain-project).
Once you run your domain project, the domain will be registered with your Mule runtime so you can refer to this domain from your project.
Referring to Shared Resources in Your Mule Project
Here you have two options to refer to the resource from your Mule project:
Using the mule-deploy.properties file.
Using the mule-project.xml file.
Here, you open the mule-deploy.properties file and configure the domain properties value as "first-mule-domain-project" as shown in the below figure.
Click on mule-project.xml; then you will be able to see a list of all domains available in your Mule ESB and you can select the domain "first-mule-domain-project" as shown below.
As you have associated your Mule project named "object-store" with the domain "first-mule-domain-project," you can now access the HTTP listener shared resource named "HTTP_Listener_Configuration" from your project, as shown below.
In my project named "object-store," I didn't create that HTTP listener for my HTTP inbound connector, but I was able to access "HTTP_Listener_Configuration" from my Mule domain project.
I hope this helps you understand shared resources and Mule domain project.