Why Domain Project ?

Introduction

Mule has the concept of Domain Project to share common resources. But as per the documentation there are some limitations of using Domain Project to share resources. Here are the main limitations as per the documentation,

  • Defining flows, subflows, or any message processors as shared resources is not supported.
  • To share a WMQ connector as a shared resource, you need to remove the mule-transport-wmq-ee-.jar file from the $MULE_HOME/lib/mule/per-app/ directory and remove all the native jars for WMQ connectivity in your application’s $MULE_HOME/apps//lib/ directory. Place all these jars in the $MULE_HOME/domains//lib/ folder instead.
  • Adding properties in the configuration files of applications that use shared resources can result in issues, as these properties are shared with other apps in the domain and there may be conflicts. You can instead set environment variables.
  • Only the following connectors and related specifications can be specified as shared resources at this time:
    • HTTP/HTTPS (both endpoints and connectors)
    • VM
    • TLS Context elements
    • JMS
    • JMS Caching Connection Factory
    • Database
    • WMQ
    • JBoss Transaction Manager
    • Bitronix Transaction Manager

But why to use Domain Project ?

I am not totally sure what is the main purpose of this Domain Project concept if we can NOT share some important common flows. For example, suppose we have some exception strategy flows which are common among various projects. So as per the documentation Domain Project will not serve our purpose.

My Argument

On the other hand , Mule has this out of the box concept where every flow is treated as spring bean.

So my argument is why should not we create a project and put all the common flows, resources (HTTP,VM etc connections ) and export it as jar and use it as dependency in other projects and load the flows as spring bean.

Experiment

In this experiment , first I will create a project with shared resources. For simplicity I am creating the following shared resources.

  1. One HTTP listener.
  2. Common exception handling strategy.

And most importantly I am exporting this project as jar file instead of conventional zip . Here is the source code of the project. In this project, I have two flows only.

connections.xml

screen-shot-2017-01-03-at-5-16-22-pm
connections etc.

This is an empty flow without any flow elements. It only contains a HTTP Listener configuration.

my-common-flows.xml

This configuration file contains a single flow called  common-exception-handling.

common-flow
Common Exception Flow.

init-DEV.properties

Also I have a simple property file with a simple property as shown below.

init-dev-properties
init-DEV.properties

pom.xml

Most importantly I am not using the zip packaging format in the pom.xml file. Instead I am packaging it as jar. Please check this part of the pom.xml file as shown below,

pom
pom.xml

Using the common resources

Now we are going to use this common resource in a project. The source code is available here. So, first of all we will modify the pom.xml file of the project and insert dependency of the common resource project we have created above. Here is a part of the pom.xml,

maven-dependency
use shared resources.

And that’s it. Now we can use the shared resources. Here in this project we have a simple flow where I am using the following shared resources,

  1. HTTP Listener (declared in connections.xml of the common project).
  2. Common exception handling (declared in my-common-flows.xml of the common project)
  3. A shared property (declared in the init-DEV.properties of the common project).

Here is the simple flow diagram,

use-shared-resources
Use shared resources.

The most important part in the configuration file my-domain-test.xml is the following,

spring-import
Spring Bean Import

Conclusion

The example shown above eliminates the use of Domain Project. Whatever we can share in a Domain Project we can achieve the same thing using a common project or we can achieve even more (sharing common flows).

So, what exactly is the purpose of a Domain Project ? I would appreciate your opinions.

Thanks.

Troubleshoot

On importing the shared resources in other projects , sometimes Anypoint studio fails to load the resources. To solve it, just close and open the project.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s