When working with Mule ESB, it’s likely that you will have multiple Mule applications using the same resource. For example, you have several Mule applications that are related, deployed to the same server, and some of these applications use the HTTP Listener Connector with the same host and port. So how to solve this problem? Mule Domain Project is a solution for you! In this tutorial, let’s learn about the Mule Domain Project in Mule ESB.
Mule Domain Project in Mule ESB is a project that contains common resources between Mule applications. Instead, globally Connectors are only used in multiple flows of the same Mule application, which can now be used in other Mule applications.
Every Mule application has its own domain. If you open the mule-deploy.properties file in any Mule project, you will see that we have a domain property named default.
This is the default domain of the Mule application. This means that each Mule application has its own domain and does not share any of its resources.
OK, now we will try to create a new Mule Domain Project and a normal Mule Project in Anypoint Studio as an example of how to use the Mule Domain Project. You can refer to how to create a new Mule Domain Project here and the Mule Project here.
Let’s say I created 2 Mule Projects in my workspace as follows:
In it, mule-esb-domain-project is the Mule Domain Project and mule-esb-helloworld is a Mule application that has a flow with an HTTP Listener Connector with a Logger Component as follows:
This flow will receive a request with the parameter name, which will allow us to print out the value of this parameter name using the Logger Component.
As you know, to configure the HTTP Listener Connector we have a section called General Settings that will point to the configuration for the host and port.
We will now move this configuration to the mule-domain-config.xml file in our Mule Domain Project, mule-esb-domain-project.
The contents of the mule-domain-config.xml file should now look like this:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
<?xml version="1.0" encoding="UTF-8"?> <domain:mule-domain xmlns="http://www.mulesoft.org/schema/mule/core" xmlns:domain="http://www.mulesoft.org/schema/mule/domain" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:spring="http://www.springframework.org/schema/beans" xmlns:doc="http://www.mulesoft.org/schema/mule/documentation" xmlns:http="http://www.mulesoft.org/schema/mule/http" xsi:schemaLocation="http://www.mulesoft.org/schema/mule/core http://www.mulesoft.org/schema/mule/core/current/mule.xsd http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-current.xsd http://www.mulesoft.org/schema/mule/domain http://www.mulesoft.org/schema/mule/domain/current/mule-domain.xsd http://www.mulesoft.org/schema/mule/http http://www.mulesoft.org/schema/mule/http/current/mule-http.xsd"> <!-- configure here resource to be shared within the domain --> <http:listener-config name="HTTP_Listener_Configuration" host="0.0.0.0" port="8081" doc:name="HTTP Listener Configuration"/> </domain:mule-domain> |
To enable our mule-esb-hello-world project using the Mule Domain Project, open the mule-project.xml file in this project and edit the Domain section as follows:
At this time, our mule-esb-helloworld project will look like this:
Now, running the mule-esb-helloworld project, you will see the following result:
1 2 3 4 5 6 7 8 9 10 11 12 13 |
INFO 2018-02-26 23:06:10,912 [main] org.mule.module.launcher.StartupSummaryDeploymentListener: ********************************************************************** * - - + DOMAIN + - - * - - + STATUS + - - * ********************************************************************** * default * DEPLOYED * * mule-esb-domain-project * DEPLOYED * ********************************************************************** ******************************************************************************************************* * - - + APPLICATION + - - * - - + DOMAIN + - - * - - + STATUS + - - * ******************************************************************************************************* * mule-esb-helloworld * mule-esb-domain-project * DEPLOYED * ******************************************************************************************************* |
That is so successful.
Now, if you request to the application with http://localhost:8081/hello?name=Khanh, the console will print the log as follows:
1 2 3 4 5 6 7 |
******************************************************************************************************* * - - + APPLICATION + - - * - - + DOMAIN + - - * - - + STATUS + - - * ******************************************************************************************************* * mule-esb-helloworld * mule-esb-domain-project * DEPLOYED * ******************************************************************************************************* INFO 2018-02-26 23:10:03,437 [[mule-esb-domain-project].HTTP_Listener_Configuration.worker.01] org.mule.api.processor.LoggerMessageProcessor: Hello + Khanh |
Hari
Can you please let me know how we can config the *.properties files with domain project.As i was using TLS password etc from this file and i want use other variable from this file.
AM using this project with out maven.