Anypoint Clustering with MuleSoft

Jitendra Bafna
Another Integration Blog
6 min readApr 1, 2023

Anypoint Clustering is the set of the servers that acts as a single deployment or High Available unit. In simple terms, all the servers are clustered together and they communicate and share information through a distributed share memory grid. There can be up to 8 servers in the one cluster.

Source — MuleSoft Documents

Anypoint Clustering is supported by the Hazelcast. The default behavior of the Hazelcast to determine the port from 5701 and it auto increment from that port number to establish successful connection on the other servers.

Anypoint Clustering supports 2 types of the clustering.

  • Unicast Clustering — When Unicast Clustering is created in the Anypoint Platform, it will push the IP Address of server to the mule-cluster.properties file located at $MULE_HOME/.mule. Any new server is added or removed from the cluster, it would be included in the files and all servers needs to be restarted.
  • Multicast Clustering — When Multicast Clustering is created in the Anypoint Platform, additional Network privileges required. There is one prerequisite for setting up the Multicast Clustering that it needs to be enabled on the infrastructure. The multicast clustering must be enabled on the IP Address 224.2.2.3 and UDP port 54327 open on the servers. In case of muticast clustering, you don't need to restart the servers if you added or removed extra server from/to cluster.

Benefits of Anypoint Clustering

  • Clustering helps in improving application performance by dividing the workload between nodes in the cluster.
  • Horizontal Scaling can be done easily whenever required.
  • Automatic coordination of access to resources, such as files, databases, and FTP sources.
  • Automatic load balancing of processing within a cluster.
  • Improve Performance, Automatic Failover, High Availability.

How to setup Unicast Clustering?

Here is the video tutorial explaining how to setup Unicast Clustering.

How to setup Multicast Clustering?

Here is the video tutorial explaining how to setup Multicast Clustering.

Enabling Persistent Object Store Using JDBC database with Anypoint Clustering

To enable, Persistent object store using JDBC database required few steps and there are few prerequisites.

Below list of the relational databases supported

  • MySQL 5.5+
  • PostgreSQL 9
  • Microsoft SQL Server 2014

To enable persistent object store, add below list of properties to {MULE_HOME}/.mule/mule-cluster.properties. This properties needs to be add to all nodes in the cluster.

  • mule.cluster.jdbcstoreurl: JDBC Connection URL to database
  • mule.cluster.jdbcstoreusername: Database username
  • mule.cluster.jdbcstorepassword: Database user password
  • mule.cluster.jdbcstoredriver: JDBC Driver class name
  • mule.cluster.jdbcstorequerystrategy: SQL dialect (It can be mysql, mssql, postgresql)

In our article, we will use MySQL as a Database for persistent object store and value for above properties will look like this.

mule.cluster.jdbcstoreurl=jdbc:mysql://localhost:3306/object_store
mule.cluster.jdbcstoreusername=root
mule.cluster.jdbcstorepassword=sqlserver12345
mule.cluster.jdbcstoredriver=com.mysql.cj.jdbc.Driver
mule.cluster.jdbcstorequerystrategy=mysql

In above example, I have used object_store as database. You can provide any name according to your need and make sure database is created before adding above properties.

Now, you need to copy driver file to {MULE_HOME}/lib/user. In my case, I have copied mysql-connector-java-8.0.26.jar file and that is MySQL driver file will be used to enable connection with MySQL database.

Once above configuration is done, you just need to restart the cluster.

The database’s tables are created automatically once you deploy application having persistent object store, as this feature creates tables for each different object store that you want to persist.
Two tables are created per object store:

  • One table stores data
  • Another table stores partitions.

Recommendation for Object store Database

  • Create dedicated Schema or Database that can be only used by JDBC Object Store.
  • Always keep in mind that the data storage needs to be hosted in a centralized DB reachable from all nodes.
  • The database username configured for JDBC Object Store needs to have permission to:
  • Create objects in the database (DDL), CREATE and DROP for tables.
  • Access and manage the objects it creates (DML), INSERT, UPDATE, DELETE, and SELECT.

Here is video tutorial explaining how to enable persistent Object Store Using JDBC database.

Implementing Competing Queue Consumer Pattern with Anypoint Clustering

Competing queue consumer patterns enable the processing of messages in parallel by multiple consumers from the same channel. This pattern is very useful when you want to process a series of small tasks asynchronously in parallel by multiple consumers of the same pool instance.

In an active-active model, there is no primary node. However, one of the nodes acts as the primary polling node. This means that sources can be configured to only be used by the primary polling node so that no other node reads messages from that source.

This feature works differently depending on the source type:

  • Scheduler source: only runs in the primary polling node.
  • Any other source: defined by the primaryNodeOnly attribute. Check each connector’s documentation to know which is the default value for primaryNodeOnly in that connector.-

In the JMS connector’s configuration, users can configure the attribute primaryNodeOnly to define whether a message will be picked by the primary node or any node in the cluster.

In other words:

  • If the primaryNodeOnly attribute is false, the clustering works in active-active mode.
  • If the primaryNodeOnly attribute is true, the clustering works in active-passive mode.

To implement the competing queue consumer pattern, the application has to be deployed on a cluster with a queue listener and you need to make sure the attribute primaryNodeOnly is set to false. This will ensure that all the nodes in the cluster have the applications deployed with a queue listener that reads the messages concurrently and processes them asynchronously.

<jms:listener doc:name="On New Message" doc:id="49714fr4–8ac7–4a09-a3f8–111b982758a8" config-ref="JMS_Config" destination="TestQueue" numberOfConsumers="1" onlyPrimaryNode="false">
<jms:consumer-type >
<jms:queue-consumer />
</jms:consumer-type>
</jms:listener>

In the diagram above, it is showing the message is sent to multiple consumers in a round-robin way because in the JMS listener configuration, the attribute onlyPrimaryNode is false. This means all nodes can actively listen to the queue and process the messages concurrently as shown in the above image.

How Anypoint Clustering works with Queue and Topics?

Here is video tutorial explaining how Anypoint Clustering behave in case of Topic and Queue.

How to setup Anypoint Clustering on the Docker?

Here is the video tutorial explaining how to setup Anypoint Clustering on the Docker.

Anypoint Clustering Architecture

Do we need external or third-party load balancer for HTTP workloads?

Yes, for HTTP workloads there is need to configure external load balancer.

How many servers can be in the single cluster?

There can be up to 8 servers in the single cluster. Minimum 2 nodes to form cluster.

Do I need to restart all the existing servers if we are adding new server to the cluster?

In case of Unicast Clustering, we need to restart the cluster and it will restart all the servers in the cluster. In case of Multicast Clustering, we don’t have to restart the cluster.

Can we create Cluster manually without registering the server in the Control Plane?

Anypoint Clustering can be created manually by adding mule-cluster.properties on all the servers that needs to be part of Anypoint Clustering in $MULE_HOME/.mule directory.

Add below properties in the mule-cluster.properties file.

......
mule.cluster.nodes = <IP Address of all server comma-separated>
mule.cluster.multicastenabled = true
mule.clusterId = <Cluster_Id>
mule.clusterNodeId = <Cluster_Node_Id>
......

Common consideration for setting up Anypoint Clustering

Here is the help article on MuleSoft.

Conclusion

Anypoint Clustering is basically used for the Customer Hosted Mule Runtime, and it is not supported for CloudHub 1.0. Anypoint Clustering is supported for the CloudHub 2.0, Runtime Fabric Manager (Self Hosted Kubernetes or RTF Applicance), Customer Hosted Mule Runtime.

--

--

Jitendra Bafna
Another Integration Blog

I am Jitendra Bafna, working as a Senior Solution Architect at EPAM Systems and currently leading APIN Competency Center.