Vert.x - Main Verticle

About

A main verticle is a main entry verticle that deploys other verticle.

Example

public class MainVerticle extends AbstractVerticle {

  @Override
  public void start(Promise<Void> promise) {

    // You get the config from the command line
    JsonObject conf = config();
    
    // Deploy database verticle
    Promise<String> dbCompletionHandler = Promise.promise();
    vertx.deployVerticle(new DatabaseVerticle(), dbCompletionHandler);

    // On completion, deploy the http web server 
    // Note id is the deployment id
    dbCompletionHandler.future().compose(
      id -> {

        Promise<String> httpVerticleDeployment = Promise.promise();
        vertx.deployVerticle(
          new VerticleHttpServer(),
          httpVerticleDeployment);

        return httpVerticleDeployment.future();

      }).setHandler(ar -> {   // <7>
      if (ar.succeeded()) {
        promise.complete();
      } else {
        promise.fail(ar.cause());
      }
    });

  }
}

Powered by ComboStrap