Domains projects in mule are a way to share resources among multiple mule applications. Think of it just like declaring global connector configurations but instead of sharing the configurations within multiple flows in a single application, it is now shared across multiple flows and multiple applications. Every mule project is associated to a domain. If you observed the mule-deploy.properties, by default the domain value is set as “default”. This means every project has its own independent domain and no application is sharing any resources outside its boundary.
The most simple/common scenario for using domains can be if you want to share the same host and port among multiple projects, you can declare the http connector within a domain project and associate the domain project with other projects. Doing this also allows to control thread settings, keystore configurations, time outs for all the requests made within multiple applications. You may think that one can also achieve this by duplicating the http connector configuration across all the applications. But, doing this may pose a nightmare if you have to make a change and redeploy all the applications.
If you use connector configuration in the domain and let all the applications use the new domain instead of a default domain, you will maintain only one copy of the http connector configuration. Any changes will require only the domain to the redeployed instead of all the applications.
You can start using domains in only three steps:
- Create a Mule Domain project
- Create the global connector configurations which needs to be shared across the applications inside the Mule Domain project
- Modify the value of domain in mule-deploy.properties file of the applications
Below are details of above three steps
1. Create a Mule Domain project
This can be done by choosing File–>New–>Mule Domain Project
Once the project is created, you will notice that the domain project doesn’t have app folder(src/main/app). This project has only two folders:
- src/main/domain – This folder contains two files; mule-deploy.properties and mule-domain-config.xml.
- src/main/resources – This folder is initially empty and used to hold any domain referenced resource files
2. Create the global connector configurations
Open the mule-deploy.properties file and add the connector configuration. Below screen shot highlights all the additions done for adding http connector configuration:
3. Modify the value of domain in mule-deploy.properties file
As highlighted below, modify the domain value of the mule-deploy.properties file inside the application to use domain. Once you do this change, you can start using the connector defined in domain from your application.
Things to be aware while using domains
If you are deploying domains/projects using domains, be aware that you need to copy the domain inside mule/domains folder instead of mule/apps folder.
Domain projects don’t support minor versions which means, if your domain project name is httpdomain, you can deploy the domain project as httpconnector.1.0 but you can not deploy the same as httpconnect.1.2. This is a strange behavior which was observed.
If you are using environment specific properties in your app and loading the properties on runtime based on a environment value specified in your wrapper.conf file, make sure you also have environment specific property file in the domain. Even if you are not loading the properties from domain, you still need to have an empty file in this situation. For ex; if you have properties in the application as app-test.properties, app-prod.properties and loading the file based on the environment on runtime, you will need to have similar property file in domain like domain-test.properties, domain-prod.properties. If this is missing mule application deployment will complain about the property file missing on domain.