Shared Resources or Mule Domain Project

         I want to talk about Shared Resources or Mule Domain Project. It’s a very powerful concept in mule and if, you know how to use it you will make the minimum effort to achieve maximum result. Suppose, you need to create five mule projects, all five projects used same database and each project is dependent on each other. In that situation you can use the Mule Domain concept.
          Domain 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 with 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 simplest 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 controlling thread settings, keystore configurations, timeouts 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 applicant
        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.

There are a few simple steps to create a mule domain project as follows.

Step: 1

         Create a Mule Domain project

This can be done by choosing Anypoint Studio menu bar.
              Mule Domain Project->

Enter project name and select mule runtime server.

After pressing the Next button new window will open, again press the Next button and finally press Finish button. You have successfully created Domain Project in Anypoint Studio.
Open the mule-domain-config.xml file and add the connector configuration. Below screen shot highlights all the additions done for adding HTTP connector configuration:

Step: 2

         Create a Mule project (Client Domain 1)

         Create simple mule project in anypoint studio, go to anypoint studio menu bar.
              Mule Project->
Enter project details like as project name, mule runtime server.  
        After pressing the Next button new window will open, again press the Next button and finally press Finish button. You have successfully created the domain client project in any point studio. Next, drag it HTTP connector, logger within the mole flow. You can see a sample screen shot below. In that, the client domain project indicates some error because I can’t define host, port no, base path etc.
Open mule-project.xml file and select mule project domain listener name. Below screen shot highlights all the additions done.
Open an HTTP connector and go to the general properties. Select connector configuration filed and set Main Domain listener name. Below screen shot highlights all the additions done.
Suppose, you have to check the HTTP connector configuration, then see below screen shot after select listener, it’s automatically set the Main Domain host, port and base path by default.
Open Logger writes any message and save it (error automatically remove).


Create a Mule project (Client Domain 2)

You have created a multiple mule project using step 2. As I already created another mule client project.

Step: 3

        Below screen shot highlights on the screen main domain project, and mule domain client. All mule domain clients are configured using the main domain listener.

Step: 4

        Run domain project in anypoint studio; go to anypoint studio menu bar.
      Run As->
              Mule Application (Configure)->
Edit domain project configuration. Suppose you would like to run both client 1 and client 2 at the same time, then click on the tick. Finally, press Run button.
See the anypoint studio console window, both project are deployed successfully. 

Step: 5

        Open any browser window and enter main domain HTTP connection like as host, port and main path. Then again enter client base path on browser header and press enter button on keyboard. 

Step: 6

         See the console window on anypoint studio tool; you can see the output of mule domain project, sample screen shot in below mention screen.

Using above steps you can easily create Share Resources or  Domain project in Anypoint Studio tool.

Sample of Share Resources or  Domain project example are also provided. Just Click on below link…
                                            Download, Sample Share resources or Domain project
If you like this blog, then please subscribe and suppose you have any queries or suggestions then comment below.

3 thoughts on “Shared Resources or Mule Domain Project”

  1. I'm following the same steps but after deploying my application it get failed.
    In Console:
    ERROR 2017-01-19 17:55:59,014 [main] org.mule.module.launcher.domain.DefaultMuleDomain: null
    org.xml.sax.SAXParseException: cvc-elt.1: Cannot find the declaration of element 'domain:mule-domain'.

Leave a Reply

Your email address will not be published. Required fields are marked *