sharing resources - mule

12
Sharing Resources - Mule - Anil Kumar. V 1

Upload: anil-kumar-v

Post on 16-Jan-2017

181 views

Category:

Technology


3 download

TRANSCRIPT

Page 1: Sharing Resources - Mule

Sharing Resources - Mule- Anil Kumar. V

1

Page 2: Sharing Resources - Mule

Mule is flexible and supports sharing of connectors as common resources. In many scenario’s, we often require to share the common resources between the applications which are deployed under the same “Domain”.

The advantage of sharing the resources, allows multiple applications/development team(s) with in the same domain to work with the same set of pre-configured connectors.

For example, application a and application b both require inbound HTTP listeners which are consuming the same port “8989”. In this scenario, we can create only ONE listener configuration and share between the two applications a & b.

At this current stage, only the following connectors can be used as shared resources: . HTTP/HTTPS

. VM . TLS

. JMS . JMS Caching Connection Factory . Database . WMQ . JBoss Transaction Manager . Bitronix Transaction Manager

2

Page 3: Sharing Resources - Mule

3

How can we create SHARED RESOURCES????

To create shared resources, follow these steps:

1. Create new domain project2. Define the shared resources3. Create application(s) and associate to the domain4. Test the application(s) by deploying the domain and the application(s)

Page 4: Sharing Resources - Mule

4

Step 1: Create new domain projectcreate domain project in Anypoint Studio, by selecting the top menu bar select File > New > Mule Domain Project

Page 5: Sharing Resources - Mule

5

After performing Step 1, you will see “mule-domain-config.xml” file under src/main/domain as shown below:

Step 2: Add an HTTP connector as a shared resources viz., “Shared_HTTP_Listener_configuration” to “mule-domain-config.xml” which is created in previous step.

Code snippet: <http:listener-config name="Shared_HTTP_Listener_Configuration" host="localhost" port="8989" doc:name="HTTP Listener Configuration"/>

Page 6: Sharing Resources - Mule

6

Step 3: Now its time to create Mule Project viz., “Application A” and attaching it to the domain project created in Step 1.

Step 3.1: Create project in Anypoint Studio, by selecting the top menu bar select File > New > Mule Project

Page 7: Sharing Resources - Mule

7

Step 3.2: Open the “application_a.xml” and drag & drop the HTTP Endpoint from the palette to the canvas. If we check the “Connector Configuration” the drop down list is empty, wait a minute where is the “Shared Resource” that we created in previous Steps?

Hmmm…. We forgot to add this project to the “Domain” project. To do so, open the “mule-project.xml” under “application_a” project and change the “Domain” name from the drop down list to “mySharedResourcesDomain” as per below figure.

Page 8: Sharing Resources - Mule

8

Step 3.3: Now open the “application_a.xml” again and you notice that the “Connector Configuration” is pre-populated with the “Shared Resource” that we created

in previous Step.

HURRAY!!!!!

And set the path to “/appa” then add a set-payload transformer to the flow with value “You are viewing message from Application A using Shared Resources”.

Step 3.4: Now its time to create another Mule Project viz., “Application B” by repeating from Step 3, with below changes to “Application B”

. Path to “/appb” . Payload message to “You are viewing message from Application B using Shared Resources”

Page 9: Sharing Resources - Mule

9

Step 4: Now its time to test the Domain and the associated applications.Right click on the “mule-domain-config.xml” and select “Run Configurations” from “Run As”

Select the “mysharedresourcesdomain” form the “Run Configurations” dialog box (make sure that both the applications are ticked when selecting the “shared domain” project) and then click on “Run”.

Page 10: Sharing Resources - Mule

10

Step 4.1: Lets check the console, you will notice that bot the applications (a & b) are started along with the domain.

Hurray!!! Both the applications are successfully deployed. Now its time to check the applications for the results.

Application A is using the URL http://localhost:8989/appa and the result is displayed in browser:

Application B is using the URL http://localhost:8989/appb and the result is displayed in browser:

Page 11: Sharing Resources - Mule

11

Now you know how to use Shared Resources among multiple applications. Like mentioned in previous slide(s), you can use the shared resources:

. HTTP/HTTPS . VM

. TLS . JMS . JMS Caching Connection Factory . Database . WMQ . JBoss Transaction Manager . Bitronix Transaction Manager

Page 12: Sharing Resources - Mule

12