Tuesday, December 13, 2016

How to create a Domain Project in Mule Soft ESB

Mule Soft ESB provides the facility to share the resources with other projects, all you need to create a domain project and share the connector, resources, properties etc. with others projects. If you create a project individually then every project gets its own domain which is “default domain”. It means no project shares their resources with other project.

For example if you have created a project and want that project to be run on a particular port then you can’t run any other project but if you create a domain project and share its port and base URL then only by the last part of the URL you can change your flow.


To create a domain project, go to File—New—and select “Mule Domain Project”.


I have given my project name as “MuleDomainTest”.


Once you create a domain project, you can see 2 files there in project explorer.



  • mule-deploy.properties
  • mule-domain-config.xml


You need to add below line in the given XML in “xmlns:domain

,

Now you can add below HTTP connector with your port number and name etc.

<http:listener-config name="http_listner_cd_domain" host="0.0.0.0" port="8086" connectionIdleTimeout="60000"/>
    <http:request-config name="http_request_cd_domain" host="0.0.0.0"  port="8086" responseTimeout="60000"/>


Make sure that you don’t have any error in compilation.

Code:

<?xml version="1.0" encoding="UTF-8"?>
<domain:mule-domain xmlns:domain="http://www.mulesoft.org/schema/mule/ee/domain" 
xmlns="http://www.mulesoft.org/schema/mule/ee/domain"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
xmlns:http="http://www.mulesoft.org/schema/mule/http"
xmlns:tls="http://www.mulesoft.org/schema/mule/tls"

xsi:schemaLocation="http://www.mulesoft.org/schema/mule/ee/domain
http://www.mulesoft.org/schema/mule/ee/domain/current/mule-domain-ee.xsd
http://www.mulesoft.org/schema/mule/http
http://www.mulesoft.org/schema/mule/http/current/mule-http.xsd
http://www.mulesoft.org/schema/mule/tls
http://www.mulesoft.org/schema/mule/tls/current/mule-tls.xsd
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-current.xsd
http://www.mulesoft.org/schema/mule/core
http://www.mulesoft.org/schema/mule/core/current/mule.xsd">
    <!-- configure here resource to be shared within the domain -->
    <http:listener-config name="http_listner_cd_domain" host="0.0.0.0" port="8086" connectionIdleTimeout="60000"/>
    <http:request-config name="http_request_cd_domain" host="0.0.0.0"  port="8086" responseTimeout="60000"/>

</domain:mule-domain>


Now to test this domain project I am creating a small project which gives a string output. So my first project is “TestMule”. Open the “mule-project.xml” of this project and select the “MuleTestDomain”  (Which we have created to test) from the domain drop down button.



You can see the connector is coming in “connector configuration” for “TestMule” project. Once you select this connector means you have started sharing connector of MuleDomainTest. Give the path as “/testmule”. I have added payload as “Hello Mule” here.



In the same way create another project and with the name of “TestHelloWorld” and follow the above process and select your MuleTestDomain connector. Here just change the path with “/testhelloworld”. I have added payload as “Hello World” here.



To run the both project simultaneously, right click on project go to “Run as” and then click on “Run Configurations”.




You can see here 2 projects are coming under our new domain. Select both project “testhelloworld” and “testmule” and click on Run button.




You can see the both project have been deployed under “MuleDomainTest



Now to test their sharing, hit the both below URL and check their output by just changing the URL path.
  • http://localhost:8086/testhelloworld
  • http://localhost:8086/testmule




In the above screen you can see that both project are running in same domain and both has common base path.