Sharing resources with mule

Preview:

Citation preview

Sharing resources with MuleBy Anirban Sen Chowdhary

We often require to share a resource within multiple application or multiple project.For example, we can share our resources like HTTP, VM, JMS or any other connector among multiple Mule application and can use within those different application.

How can share our resource between multiple Mule application ???

Mule has the ability to select a connectors as common resources and expose them to all applications deployed under a same domain. We need to create a domain under which resources can be shared.These resources are known as Shared resources, and to host these we need create a Mule Domain Project and then add reference to it on each of the projects. Once we define, any Mule application associated with a particular domain can access resources.

This idea of Shared resources allows multiple development teams to work in parallel using the same set of reusable connectors.

Creating a domain to share resources.

We start with creating a Mule Domain project first in our Anypoint studio.

Let’s give the project name as Shared_Domain_Project1

And now we will ad a resource, for example a HTTP connector that will be shared across multiple application.Here we can see we have used the connector name as HTTP_Shared_Listener and this will be shared among multiple application.

Adding an application in the domain

Now we will add application in the domain called shared_domain_project1. This application will reuse the shared HTTP connector called HTTP_Shared_Listener_Configuration. We will call it as application1.

We will create a flow in the application that will refer shared HTTP connector HTTP_Shared_Listener_Configuration

Lastly, we will associate our application1 with the domain shared_domain_project1 we created in our mule-project.xml of our application

Adding another application in the domain

We will now add another application in the same domain called shared_domain_project1. This application will also reuse the shared HTTP connector called HTTP_Shared_Listener_Configuration. We will name it as application2.

We will again repeat the same and create a flow for the application2 that will refer shared HTTP connector HTTP_Shared_Listener_Configuration

Repeating the same process, we will associate our application2 with the domain shared_domain_project1 we created in our mule-project.xml of our application.

Now, both of our application are associated with same domain and will share the same HTTP connector.

Deploying our domain and associated applications

We will select our domain project and will select Run As Run Configuration

We can see, by default the domain is associated with both the application. We can manually select the application we want to deploy with this domain. In our case, we will deploy both.

Testing our domain applications

We can see, the domain and it’s both applications has been deployed successfully.

So, if we hit url :- http://localhost:8081/app1 which is used by application1 in the domain, we will find the following results in the browser:-

And if we hit url :- http://localhost:8081/app2 which is used by application2 in the domain, we will find the following results in the browser:-

So, we can clearly see here both the application is using the same HTTP connector among them.

Testing our domain applications on Standalone server

To, deploy the domain in Mule Standalone server, we need to create the .zip file of the domain project and put it MULE_HOME/domains folder, then it deploys the application

Now, the best part is we will see our Domain is deployed successful and not only that, both the applications associated with it is automatically deployed :-

If we got to our MULE_HOME/domains folder location, we will see that the domain got deployed and it created an anchor.txt file with the successful deployment :-

Also if we got to our MULE_HOME/apps folder location, we will both our applications associated with it deployed and both have created an anchor.txt file with the successful deployment :-

We can now test the applications again in the same way we did it with our Studio.

Conclusion…..

Here it was a small demonstration to share a resources among multiple applications. Apart from HTTP,we can do it for other resources like VM, JMS, Database, WMQ, Jboss Transaction Manager and many more.

So at the end I can only say that, let’s spread our knowledge and expand our Mule community.

Thank You

Recommended