INTEGRATION USING MULE

Mule as Azure Worker Role using Anypoint Studio

In this post, I am attempting to explain steps involved in creating Worker Role and running Mule using Azure toolkit for Eclipse.

Step1: To begin, open Anypoint Studio and install Azure toolkit for Eclipse by choosing Helpà Install New Software and entering the URL: http://dl.msopentech.com/eclipse

Reference: https://github.com/MSOpenTech/WindowsAzureToolkitForEclipseWithJava

1

Note: I am using the newest beta version Anypoint studio 6 and mule runtime 8.0 but these steps should work fine for the older versions as well.

Step2: Once the toolkit is successfully installed, open a new project and select Azure Deployment Project

2

3

Enter the name of the project and hit Next. Don’t hit Finish at this point as that will skip the additional configurations which are required.

Step3: Once Next is clicked, it will bring up below window which provides options regarding how to use JDK.  For the scope of this blog, select the option Deploy my local JDK (Windows only) as this is required for using Azure Emulator to test locally.

4

Once this setting is done, hit Next. Again don’t hit Finish at this point yet.

Step4: Now we will need to choose option to deploy Mule server. Unfortunately, this option is not available in the toolkit. However, we can edit the configuration file used by the toolkit to deploy the type of server. To see the path of the file, click on Customize

5

 

This should open the componentsets.xml. Observe the path of this file and open the xml in any editor. In the componentsets.xml navigate to the end and add below section before the closing tag of </componentsets>.

At high level, the configuration indicates following:

  1. Which batch file should be run to start mule server – referenced by the detectpath
  2. What is the location to copy any app – referenced by SERVER_APPS_LOCATION
  3. Where can the server be deployed from – this is only when we choose not to use local copy
[xml] <componentset name="Mule Standalone" type="server" detectpath="bin/mule.bat">
<startupenv name="MULE_HOME" value="${placeholder}" type="server.home"/>
<startupenv name="SERVER_APPS_LOCATION" value="%MULE_HOME%\apps" type="server.app.loc"/>
<component importsrc="${placeholder}" importmethod="copy" type="server.deploy" deploydir="%DEPLOYROOT%" deploymethod="copy"/>
<component deploydir="%SERVER_APPS_LOCATION%" deploymethod="copy" importsrc="${placeholder}" importmethod="${placeholder}" importas="${placeholder}" type="server.app"/>
<component deploymethod="exec" deploydir="%MULE_HOME%\bin" importas="mule.bat" type="server.start"/>
<downloads>
<download name="Mule 3.8" licenseurl="https://www.mulesoft.com/sites/default/files/Beta%20Trial%20License_20151021.pdf" cloudsrc="https://s3.amazonaws.com/MuleEE/mule-ee-distribution-standalone-3.8.0-M1.tar.gz" home="%DEPLOYROOT%\mule3.8" default="true"/>
<download name="Mule 3.8.0" licenseurl="https://www.mulesoft.com/sites/default/files/Beta%20Trial%20License_20151021.pdf" cloudaltsrc="https://s3.amazonaws.com/MuleEE/mule-ee-distribution-standalone-3.8.0-M1.tar.gz" home="%DEPLOYROOT%\mule-3.8.0"/>
</downloads>
</componentset>

[/xml]

Once this is copied, reopen the project configuration wizard and now you should see Mule Standalone as an option in the drop down.

6

Choose the option to Deploy my local server as we need this to be tested locally using the Emulator.

7

Note: The folder mule3.8 is the folder containing 3.8 runtime for mule

After this click Next to configure the Application to be deployed

Step5: At this step we need to configure the app(s) need to be deployed on the Mule server. By default, HelloWorld.war is added, remove this and add the mule app you need to deploy.

For this blog, I am using a simple mule app (HelloMule-1.0.0-SNAPSHOT.zip) packaged using maven. The app has http inbound end point and sets payload response as – Hello Mule #[server.dateTime.getTime()]

8

NOTE: You have to make sure the zip file HelloMule-1.0.0-SNAPSHOT.zip exists in the folder HelloMule. Usually when maven is used to build the final zip will reside under HelloMule\target\ folder. This path can be changed later in the package.xml if you want it to be picked from the target folder.

One issue noticed is, even though we mention in the dialog to import file as .zip, the file was copied as HelloMule-1.0.0-SNAPSHOT.zip.jar. If you see this, please go ahead and delete the HelloMule-1.0.0-SNAPSHOT.zip.jar and copy HelloMule-1.0.0-SNAPSHOT.zip under approot folder manually.

Once this configuration is complete, hit Finish.

Step6: You should now see the Azure project successfully created

9

 

Everything which was configured for JDK and Mule server will be inside package.xml. This xml is used to generate the worker role package. In case you require any modifications to the JDK or Mule Server or the app to be deployed, you can do it on the package.xml

Step7: You can now run this project by clicking on “Run in Azure Emulator” Icon

10

Once you hit this, you should be able to see the project building. If there were any errors in the project/configuration, the deployment will be stopped until the errors are fixed.

One of the common errors is the path exceeding more than 256 characters. If you run into this issue, you may have to copy AnypointStudio and the other directories to the base drive location instead of subfolders.

Step8: By now if everything builds successfully, you should see Azure Emulator started and also Mule Standalone kicked off with successful deployment of HelloMule application. Below screenshots show the Mule Standalone and Azure emulator running side by side:

11

You should be able to confirm the application is deployed by navigating to the endpoint exposed by the HelloMule application

12

Although you are running this using Azure Emulator, technically, you can claim to have mule deployed as worker role in Microsoft Azure.

Improvements

Since mule is running as standalone, you may want to consider below two improvements:

  1. Have healthchecks running against the app/mule server to alert incase Mule shuts down for some reason and the Worker Role is still running.
  2. Have mule deployed as windows service (within worker role) instead of running Mule as standalone as the service provides JVM hooks
Tagged , , ,