1

I am developing microservices using vertx4 and each service is composed of multiple verticles and all are deployed as clustered(hazelcast) verticle using below code.

Vertx.clusteredVertx(options.setHAEnabled(isHa), (vertx) -> {
            ((Vertx)vertx.result()).deployVerticle(verticleName, (new DeploymentOptions()));
});

I am calling above code for each verticle in a service and multiple vertx object or instance is created.

  1. Is it correct way deploy verticles in cluster?
  2. Should I get one vertx object from clusteredVertx and use it deploy multiple verticles?
  3. What would be the advantage and disadvantage of having multiple vertx instance?

I have gone through the vertx documentation but I am not able to understand clustering particularly. I even checked some of vertx source codes like Launcher class but nothing helped me to get answers.

vel
  • 173
  • 9

1 Answers1

2

I think you are mixing two concepts, one is the Vertx instance, the other is clustering.

Each Vertx instance has and manages its own event bus and its own event loops that are best used to run many verticles. One instance of Vertx is fully capable of managing a lot of verticles and will allow them to communicate to each other over one event bus. This is the concurrency model.

Clustering needed when you need to extend and connect the event bus between multiple applications (= multiple Vertx instances) normally deployed to different JVMs and even machines.

When clustered, each Vertx instance has own event bus but instances that discover each other (how depends on clustering technology) will bridge their event buses this means that their verticles will find each other. However this bridge has its own cost and is not something you want to use for inside application communications.

So if you are talking about one application, then the usual method is to obtain a single Vertx instance and use that for deploying all your verticles. The verticle itself does not know if its mounted on a clustered Vertx or not. Except it can explicitly mount its handlers only for local usage (vertx.eventBus().localConsumer(...)) which means even in a clustered setup those handlers will not respond to messages from other instances.

Having multiple Vertx instances inside one application is not impossible but if you are not trying to bend Vertx to its extends, then this is not for you.

mohamnag
  • 2,709
  • 5
  • 27
  • 40
  • Hi @mohamnag, I am using clustered vertx for communication within one service and across individual services as well. My question was for multiple verticles within one application, should i call clusteredVertx() only one time and use it deploy multiple verticles or can I call clusteredVertx() for each verticle? – vel Apr 21 '21 at 12:48
  • 1
    might be I was not clear enough, but unless you know Vertx very well and you are bending it to its extend, you need only one instance for all your verticles, no matter clustered or not. – mohamnag Apr 21 '21 at 13:56