How to install multiple Mule Runtimes on the same Windows Server


Running multiple Mule runtime instances on the same server is possible and might be an option in some scenarios. Although it will increase the complexity of our setup and maintenance, it might help us to reduce cost, and allow for better isolation between applications or run different mule runtime versions.


In this post, we will see how to set up multiple Mule runtimes on a Windows machine, configured as windows services and registered in the Anypoint control plane. Let’s see how to do it:

Prerequisites

To follow this tutorial we need:

Download the Mule Runtime

First, we need to download the Mule runtime binary files. 
Go to https://www.mulesoft.com/lp/dl/mule-esb-enterprise and provide your details. Don’t forget to select Mule Standalone and in Product Selection and Windows as your Operating System


Once you fill in the form you’ll get an email with a link for downloading the mule runtime. Click on Download .zip and wait for it.


Set up two different Mule directories

One of the requirements to make multiple runtimes work on the same Windows server is to have the Mule binaries in separate directories. Each mule runtime needs to have its own directory.
For that, once the download of the .zip file is complete we’ll create two directories. In this tutorial we’ll create the following:

  • MULE RUNTIME 1 → C:\MULE1
  • MULE RUNTIME 2 → C:'\MULE2

Then, extract all the files from the .zip file that we’ve downloaded and copy it twice, one copy per each MULE directory:



Install the First Mule Runtime

With the previous configuration we’d be able to start both runtimes from their respectives directories. But, in a production environment, we’d normally require to install the mule runtime as a service for better control and to be able to (re)start the mule runtime automatically everytime Windows server (re)starts.

The problem is that, with the default configuration, both runtimes would register the service with the same name, which will lead to an error.

To avoid that, we need to modify the mule.bat file of each mule runtime. Let’s do it for the first one:
  • Go to the bin folder of the first mule runtime - in this tutorial we’d go to C:\MULE1\bin and Open the mule.bat file with the Notepad. 
  • In that file, go to the Customized for Mule section. You should see something like this:
###############################################
# Begin Customized for Mule
###############################################

if [ "$MULE_APP" = "" ]
then
MULE_APP="mule_ee"
fi
export MULE_APP
if [ "$MULE_APP_LONG" = "" ]
then
MULE_APP_LONG="Mule Enterprise Edition"
fi
export MULE_APP_LONG

###############################################
# End Customized for Mule
###############################################

These are the values that would be taken to create the Windows service. So, for the first mule runtime we’ll modify that section to the following:
###############################################
# Begin Customized for Mule
###############################################

if [ "$MULE_APP" = "" ]
then
MULE_APP="mule_ee_1"
fi
export MULE_APP
if [ "$MULE_APP_LONG" = "" ]
then
MULE_APP_LONG="Mule 1"
fi
export MULE_APP_LONG

###############################################
# End Customized for Mule
###############################################

Save and close the file.

Now, open the command prompt and change directory to the bin folder of the first runtime:

cd C:\MULE1\bin

A
nd from there run the following command to register the first mule runtime as a service:
mule install


Install the Second Mule Runtime

Repeat the previous step for the second runtime. 
  • Go to the bin folder of the second mule runtime - in this tutorial we’d go to C:\MULE2\bin and Open the mule.bat file with the Notepad. 
  • In that file, modified the Customized for Mule section and provide the following values:
###############################################
# Begin Customized for Mule
###############################################

if [ "$MULE_APP" = "" ]
then
MULE_APP="mule_ee_2"
fi
export MULE_APP
if [ "$MULE_APP_LONG" = "" ]
then
MULE_APP_LONG="Mule 2"
fi
export MULE_APP_LONG

###############################################
# End Customized for Mule
###############################################

Save and close the file.

Now, open the command prompt and change directory to the bin folder of the second runtime:
cd C:\MULE2\bin

And from there run the following command to register the second mule runtime as a service:

mule install


Connect the Mule Runtimes to the Control Plane

Start the Mule Runtimes

Once both Mule Runtimes are registered as services, proceed to start them. You can do it from the Services console or by running the following command from the respective bin folder of each runtime
mule start

Verify that both services are up and running:



Register the first Mule Runtime to the Control Plane

Now, head over Anypoint platform > Runtime Manager. On the left panel, click on Servers and then Add Server




In the pop-up window, provide a name for your first Mule Server and then copy the command.


Now, get back to the Windows Server and open a command prompt. From there, change directory to the bin folder of your first Mule runtime
cd C:\MULE1\bin

Next, paste the command you copied from the Runtime Manager. This is a Windows system, so don't forget to remove the ./ at the begining of the command. After that, the Mule Agent will start to be installed:




If everything works you should see the final message:


Restart the service. You can do it from the Services console or by running mule restart in the command promt.
Get back to the Anypoint Platform and verify that your Mule runtime shows Running status. 




Register the second Mule Runtime to the Control Plane

Repeat the same process for the second runtime. Add Server in Runtime Manager:

Copy the command and paste it in the command prompt, from the second runtime bin folder:



Restart the service



Verify the control plane



With that, we've got both Mule Runtimes running as Windows services and managed by the control plane.


Deploy a test application to each Mule Runtime

Time for testing - Let's see how we can deploy a helloWorld application to each Mule Runtime and verify the whole setup works.

Test Mule Runtime 1

Head over to Anypoint Studio and create a test app like this one:


Run the project or package it into a jar with Maven. Then go to Runtime Manager and click on Deploy application.  Provide a name to your app (hello-windows-1) and make sure in Deployment Target you pick up the first Mule Runtime under the Hybrid option.



Deploy the app. After a few seconds you will there's a new folder within the apps directory of your first Mule Runtime.


And once the app is deployed you will see it registered. in your first Mule server in the Runtime Manager:


Test your app. Send a GET request to your helloWorld endpoint.

Test Mule Runtime 2

Repeat the process for the second runtime - Create a new Mule project:


Get the jar and deploy it to Runtime Manager, making sure that this time you pick up the second mule runtime as target:



Verify the new app shows up in the apps directory of your second runtime and that it gets registered in the second mule runtime:



Lastly, test your endpoint and verify it works

Congratulations, you've correctly set up two mule runtimes in the same Windows server.

Previous Post Next Post