Vertx clusters typically use a Cluster Manager based on Hazelcast as it provides auto-node-discovery and group membership for the Vertx nodes in a cluster along with support for distributed data sharing.
The vertx-hazelcast jar should be on your
CLASSPATH for Vertx to detect it, and use it as the default cluster manager. The cluster could be configured using the
default-cluster.xml file found in
conf folder in the vertx installation directory.
Default Multicast Cluster
Vertx provides several command line options to support MultiCast Cluster. Simply specify
-ha command line option ( ha for high availability ) with the vertx command when trying to run a verticle or a module and Vertx would try to send multicast messages on the network trying to find out existing nodes.
TCP-IP Clustering Support
If multicast does not work, we can configure Hazelcast for full TCP/IP cluster. Lets assume we have to create a cluster of 2 machines with IP Addresses 10.40.X.Y and 10.40.A.B. We need to configure the
default-cluster.xml file for each node. To do so, open the
conf/default-cluster.xml file in the vertx installation directory on each node and make the following changes:
- Disable the multicast option
- Enable tcp-ip option and provide all or subset of cluster members’ hostnames and/or ip addresses. ( Below is the config for
Each node/machine must have the IP address of the other machine in its
default-cluster.xml configuration so that when Vertx starts, it could try and connect over TCP to this other node.
One can also specify Network Interfaces that Hazelcast should use. Servers mostly have more than one network interface so you may want to list the valid IPs. Range characters (‘*’ and ‘-‘) can be used for simplicity. So
10.3.10.*, for instance, refers to IPs between
10.3.10.0 and 10.3.10.255.
EC2 Auto Discovery
This is the real deal as most of our production instances would be deployed in AWS and Hazelcast provides EC2 Auto Discovery as of 1.9.4. It is useful when you don’t want or can’t provide the list of possible IP addresses. Here is a sample configuration: Disable join over multicast and tcp/ip and enable aws. Also provide the credentials. The aws tag accepts an attribute called “
connection-timeout-seconds“. The default value is
5. Increasing this value is recommended if you have many IP’s listed and members can not properly build up the cluster.
Hope this helps someone trying to figure out how to create a Vertx cluster