gavrmike
gavrmike

Reputation: 137

vertx-x3 cluster multiple verticles

I want to use vert.x3 in cluster mode with hazelcast with java. I have two types of Verticles:

  1. verticle for handle http requests(simple http server) (this type of verticle should be run on each node)
  2. verticle with (non-local) eventbus consumers, for contain some data (i have N parts of data, each verticle contain one part, i would like to run each part in HA mode and only one instance for each(There are N verticles of this type in the cluster)).

Verticle of type one would communicate with verticle of type two.

I also have a fatjar with all code.

And I have few questions about it.

How should I do this?
How to run cluster?
Do I run same jar on each node or need do something else?
How to run each type of verticle?
How to guarantee that only one instance of verticle of type two will run on cluster?
Does I lose eventbus messages?
Is it correct way to use vertx for this task?

Upvotes: 3

Views: 2669

Answers (1)

Paulo Lopes
Paulo Lopes

Reputation: 5801

There are several questions here I'll try to answer them all.

How should I do this?

The easiest way imho is to have a single fat jar per verticle type and each verticle should have the dependency on the hazelcast cluster manager:

<dependency>
  <groupId>io.vertx</groupId>
  <artifactId>vertx-hazelcast</artifactId>
  <version>3.3.2</version>
</dependency>

And in your shade plugin specify the manifest attributes:

  • Main-Class: io.vertx.core.Launcher
  • Main-Verticle: vertx.bc.service.Main

How to run cluster?

Now for each fat jar you can run as:

java -jar verticle1.jar -cluster
java -jar verticle2.jar -cluster

They should form a HZ cluster and be up and running. You can deploy on the same machine, or across several machines as long as your network supports multicast the default config will work for you. If you have special needs you need to customize your HZ config.

How to guarantee that only one instance of verticle of type two will run on cluster?

You can't. It is a distributed system the network should be considered unreliable so there cannot be an assumtion that you always know how many nodes of each type are running. To solve this you need monitoring tools. BTW this is not Vert.x specific but related to any distributed system/microservice architecture.

Does I lose eventbus messages?

Only if there are no consumers at the time of submission for a specific address, those messages will be lost. This relates to the previous question, to reduce this chance you should deploy more instances of a specific verticle to reduce the chance of message loss and the deployment should be across several machines to reduce the change of network split.

Is it correct way to use vertx for this task?

If you're using ha and only 1 instance this should work fine for consumer verticles, however note that the web server if for some reason dies and respawns on another host will not give what you're looking for since the http server "moved" from host1 to hostN. This means that all your web clients will now get a "Cannot connect to host" error since your application entry point is now using a different IP address.

Upvotes: 2

Related Questions