Implement Clustering in CloudHub

DZone 's Guide to

Implement Clustering in CloudHub

To ensure High Availability (HA), fault tolerance (FT), scaling, and performance for the application, a cluster can be set up in Mule.

· Integration Zone ·
Free Resource

To ensure High Availability (HA), fault tolerance (FT), scaling, and performance for the application, a cluster can be set up in Mule which acts as a single unit to provide the mentioned capabilities. The instances in a cluster are called nodes that communicate and share a distributed memory grid. Mule uses an active-active model to cluster Mule Runtime engines.


In case one node goes down, the other node will pick up failed nodes work.

In Active/Active model both the nodes (assuming cluster have two nodes only), are available to handle traffic and in case, one of them goes down, say node A, then the other one/node B will take over the load from its companion (the process is called failover) and when node A comes back up it will take back it's connections and services from node B (called failback) whereas in Active/Passive model only one server (primary node) handles all the traffic while the other node (secondary server) just sits there ready to take over if the primary node fails.

Setting Up Cluster

First, add two servers to the CloudHub. To read about how to add servers, click here


To add servers to the cluster, all the servers must be in Running state, running the same mule version and same runtime agent version. They shouldn't contain any deployed application/domain. 

Click on Create Cluster

Provide the cluster name, names can contain between 3-40 alphanumeric characters (a-z, A-Z, 0-9) and hyphens (-). They cannot start or end with a hyphen and cannot contain spaces or other characters. Select Unicast or Multicast

  • Unicast
  • Multicast
Advantage of Multicast over Unicast is servers needn't be in running state to be added to the cluster, also nodes can be added to the cluster without restarting it. 

Select Multicast, then click Create Cluster. Anypoint Platform will restart both the servers when Create Cluster is clicked to apply cluster settings. Servers will be not listed under Server panel now, to see them, go to Servers -> Click on Cluster Name.


The server with the Star symbol is the primary/master node. Though there is no primary/master node in the active-active model, one node acts as a primary polling node.

Verify Cluster Setup

Verification of cluster can be done mule_ee logs, but first, the logs for clustering need to be activated in log4j2.xml. In Mule versions from 3.3.x to 4.1.x, there is no need to edit log4j2.xml.

<AsyncLogger name="com.mulesoft.mule.runtime.module.cluster" level="DEBUG"/>
<AsyncLogger name="com.hazelcast.internal.cluster" level="DEBUG"/>

The logs will show the cluster members, their IPs, IDs. Considering the cluster created above, logs will be like below


To deploy an App in the cluster, navigate to Application ->Deploy Application. The deployment target should be the cluster. The app will be deployed on both the nodes.

deploy application

Testing Cluster Setup

Create an application with Scheduler as a source and a logger inside for each scope running for 500 iterations.


<flow name="cluster-demo-appFlow">
<scheduler doc:name="Scheduler">
<scheduling-strategy >
<foreach doc:name="For Each" collection="#[(0 to 499)]">
<logger level="INFO" doc:name="Logger"message="Server Dir=#[server.userDir]"/>
<set-payload value="Cluster Demo App" doc:name="Set Payload" />

The logger inside For Each scope is the printing Server Directory which will be used to identify which node processed the message. Since both the Mule instances are running on the same machine, IP or host can't be used to differentiate between them, hence, using the Server directory. Now deploy the application on the cluster and check the application logs for both the server.

Thanks for reading!

anypoint cloud, cluster, integration, mule, mulesoft, tutorial

Published at DZone with permission of Abhay Yadav . See the original article here.

Opinions expressed by DZone contributors are their own.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}