Search code examples
javavert.x

How can I get a reference to my deployed verticle after deploying it with Vertx?


I have a service called TestService which extends AbstractVerticle:

public class TestService extends AbstractVerticle {
  @Override
  public void start() throws Exception {
    //Do things
  }
}

I then deploy that verticle with vertx like this:

Vertx vertx = Vertx.vertx();
vertx.deployVerticle(TestService.class.getName());

How can I get a reference to my deployed TestService after vertx instantiates it?


Solution

  • You should use an alternative method for deployment:

    vertx.deployVerticle(TestService.class.getName(), deployment -> {
      if (deployment.succeeded()) {
        // here is your ID
        String deploymentId = deployment.result();
      } else {
        // deployment failed...
      }
    });
    

    If you're just interested in listing all deployed verticles then you can just request the list of ids:

    vertx.deploymentIDs()