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.
Join the DZone community and get the full member experience.
Join For FreeTo 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 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
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"/>
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.
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 >
<fixed-frequency/>
</scheduling-strategy>
</scheduler>
<foreach doc:name="For Each" collection="#[(0 to 499)]">
<logger level="INFO" doc:name="Logger"message="Server Dir=#[server.userDir]"/>
</foreach>
<set-payload value="Cluster Demo App" doc:name="Set Payload" />
</flow>
Thanks for reading!
Published at DZone with permission of Abhay Yadav. See the original article here.
Opinions expressed by DZone contributors are their own.
Trending
-
Effortlessly Streamlining Test-Driven Development and CI Testing for Kafka Developers
-
Auditing Tools for Kubernetes
-
Fun Is the Glue That Makes Everything Stick, Also the OCP
-
JavaFX Goes Mobile
Comments