Skip to content

Latest commit

 

History

History
 
 

zookeeper-examples

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 
 
 

Vertx-Clustered-EventBus-with-Zookeeper

An example of an application clustered on multiple nodes (machines) showing Vert.x event bus configuration using vertxOptions and using Zookeeper as the cluster manager.

This application consists of:

  • Sender Verticle - sending data on the event bus

  • Consumer Verticle - receiving data from the event bus

  • Node1 MainClass - A clustered Vert.x instance that should run on node1 (machine1) deploying Sender Verticle

  • Node2 MainClass - A clustered Vert.x instance that should run on node2 (machine2) deploying Consumer Verticle

Clustering Event Bus

As mentioned in Vert.x documentation: cluster managers do not handle the event bus inter-node transport, this is done directly by Vert.x with TCP connections. So the event bus configuration should be consistent on each node in the cluster, in this project we configure the VertxOptions and these options are used by the event bus. On each node we set the cluster host to be the same node’s IP address and any arbitrary port number. Note that if we want to run two Vert.x instances on the same machine we should set the cluster host to be the same IP address and we must choose two different ports to avoid conflict.

Running the project

Running Zookeeper

You must have Zookeeper server running on your machine for this example to work. In this example we use Docker to start a Zookeeper instance.

Running code

  • Same machine: Make sure Zookeeper server is running then start the two main classes from your IDE (consumer then sender). You should see the sent and received data (don’t forget to start both applications).

  • Two seperate machines: Make sure Zookeeper is running on the machine(s) whose IP(s) are set to "zookeeperHosts" property then start each main class from a different machine (consumer then sender), in each main class set the cluster host to the IP address of the machine it is running on. The Zookeeper configuration should be the same on both machines. You should see the sent and received data.