running mule as worker role on azure
TRANSCRIPT
Running Mule as Worker Role on Azure
• If you are looking for options to have Mule running in Microsoft Azure to claim PaaS, one of the best ways is by using Worker Roles. Worker Roles are VMs with IIS disabled (this can be enabled if needed) and are generally used to perform any complex processing tasks. We can leverage this ability to run Mule standalone service inside an Azure Worker Role.
• The idea is to be able to script the process of running Mule (either as a service / standalone) and deploying an app on it within Azure.
This can be achieved in two ways which I am aware of:
• Use Visual Studio to create worker role and write batch file / power shell script to run Mule with apps to be deployed• Using Azure toolkit for Eclipse and configuring the scripted process
while writing minimal lines of code
• In this blog post, I will be walking through the steps for the second approach. We will be limiting this post to testing this locally using Azure Emulator and refrain from the deployment process to Azure portal.• Note: Here is more information about approach 1.
• Step 1: 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
Note: I am using the newest beta version of Anypoint Studio 6 and Mule runtime 8.0, but these steps should work fine for the older versions as
well.
Step 2: Once the toolkit is successfully installed, open a new project and select Azure Deployment Project.
• 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.• Step 3: Once Next is clicked, it will bring up the below window which
provides options regarding how to use JDK. For the scope of this blog post, select the option Deploy my local JDK (Windows only) as this is required for using Azure Emulator to test locally.
Once this setting is done, hit Next. Again don’t hit Finish at this point yet.
• Step 4: 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.
• 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 the below section before the closing tag of </componentsets>.
At a high level, the configuration indicates following:
• Which batch file should be run to start mule server – referenced by the detectpath• What is the location to copy any app – referenced by
SERVER_APPS_LOCATION• Where can the server be deployed from – this is only when we
choose not to use local copy
• Once this is copied, reopen the project configuration wizard and now you should see Mule Standalone as an option in the drop down.
• Choose the option to Deploy my local server as we need this to be tested locally using the Emulator.
• Step 5: 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 post, 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()]
Step 6: You should now see the Azure project successfully created:
Step 7: You can now run this project by clicking on the “Run in Azure Emulator” icon:
Step 8: By now if everything builds successfully, you should see Azure Emulator started and also Mule Standalone kicked off with successful deployment of HelloMule application. The below screenshots show the Mule Standalone and Azure emulator running side by side:
Improvements• Since Mule is running as a standalone, you may want to consider the
below two improvements:
• Have healthchecks running against the app/Mule server to alert you in case Mule shuts down for some reason and the Worker Role is still running.• Have Mule deployed as a Windows service (within worker role)
instead of running Mule as a standalone, as the service provides JVM hooks.