MuleSoft — Resource sharing using domain projects

Playing around with shared resources and Mule domain projects

Amlan Mahapatra
The Mule Blog
6 min readJun 6, 2020

--

When you deploy Mule on premises, you can define global configurations like default error handlers, properties, scheduler pools, and connector configurations in such way that all other applications can access these global configurations. To do so, you have to create a mule domain project and then point it from other applications . As a result, each app in that domain can access shared resources.

Now let’s understand the advantages of Mule Domain Project:

  • Expose multiple services within the domain through the same port.
  • Share services between Mule applications through a well-defined interface.
  • Centralized configuration.
  • Reduce time for developing as well as testing.

Now understand the downside of Mule Domain Project:

  • Domain projects are not accessible from different domain.
  • You can’t deploy it in Cloudhub, you have to install to the Mule runtime engine On Premises.
  • You can’t define any flows or subflows or any other business logic.
  • You have to maintain the version of connector. Means if you use a connector in domain project whose version is 1.1.10 and in your calling application you use 1.1.11, it will give an error. You have to use the same version of connectors.

Now i think we have got the basic idea about domain project. So let’s start developing a sample domain project.

Step 1 : First create a mule domain project

Open Anypoint Studio then 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 as “mydomain”.

After creating the project you will see a canvas like

Now you can notice one thing that, its some thing different from normal canvas where we make our flow something like

And also the underlying xml of domain project starts and ends with “domain:mule-domain” and on the other hand normal mule’s xml starts and ends with “mule” tag.

Step 2 : Now configure the shareable resources

For this example we will use a http listner and a http request connector.

Now click on “Create” button , then you can see a window where search for the configurable connector.

Now we will search for “http”. But for the first time we can’t find anything.

So to load the required module, we have to choose one of these 3 option.

  • from Exchange
  • from Featured Modules
  • from Maven

In this example we are using “from Exchange”.

To do this we have to follow some steps-

1.Click on “Manage Module”

2.Click on “+” and choose “from Exchange”

3.Now search for “http” and add the module

4.Then click on “Apply” then “Apply and Close”

Now, http module is now available in the project with sockets connector and its by default comes with http connector. But notice one thing , the version of these connector. The version of the http connector is 1.5.18 and sockets connector version is 1.1.5.

Since our required modules are available , now we can create our shareable resources by clicking on “Create”.

Now search for “http” again

Now we can find the configurations for http. So lets configure these

First configure the “http listener”. For this you just have to select the “Http Listener Config” from the “Choose global Type” window and click on “ok” and configure as per your requirement. For this example I will use default configuration and give a name as “myDomainHttpListner” for identification.

Ok, now we will configure the “http request”

We will configure “ https://cat-fact.herokuapp.com/facts/random?animal_type=cat&amount=5 “ api.

To do so we just have to select the “Http Request Configuration” from the list of “Choose Global Type” window and click on “ok”. Then just configure it like

Now save it. Ok, now our domain project is ready.

Step 3: Create a Mule project which will use these global configurations

Create a new project by clicking on “File” ===> click on “New” ===> select and click on “Mule Project” and then enter your domain project name as shown in the attached screenshot as “MyCallingApplication”.

To fetch the global configuration of domain project first we have to point it from the calling application. For this just right click on calling project, in our example its “MyCallingApplication”, then click on “Build Path” then select “Configure Build Path”. And now select “Mule Project” option.

Now click on the “Domain” drop down and select our domain project which is “MyDomain”. Then Click on “Apply and close”.

Now if you open the pom.xml file of the calling application we can see the snapshot of the domain project

Now go to the canvas to make the flow. But before that please check the version of the http connector of the calling application. I already told you that the version of the connector used in both places means the domain project and calling application should be same otherwise it will give an error because you can’t use same connector of different version in one project. OK, so we are using http connector whose version is 1.5.18.

My suggestion is always go to exchange to pick the right version for the calling application means the version you used in the domain project.

Now drag a “http listener” and a “http request” connector and a “logger” like

Now click on the “http listener” to configure. And then we can select the connector configuration which we build in domain project and give a path, for this example I will use “/go” as path.

Now click on “http request” to configure in the same way. And you can find the configuration from drop down and make some additional configuration for hitting the api.

Ok. Development is done. Now time to test. So lets run the calling application means for this example its “MyCallingApplication”. No need to run the domain project.

If all steps and configurations are perfect then during the deploying we can find some log message in log, like-

After deploying, we can test through the postman rest client

Hope this tutorial helps you understand shared resources and Mule domain project, will come back later with more stuffs.

--

--

Amlan Mahapatra
The Mule Blog

Java| Spring-Hibernate | Certified Mulesoft Developer | Foodie | Nocturnal