简体   繁体   中英

How do I start a Vertx 3 Verticle from a main method?

How do I start a Verx 3 Verticle from a main method? I have figured out how to start it from unit tests and the getting started guide explains how to build a fat jar. But how do I simply start it from a main method for the purpose of debugging, profiling etc?

Simply do

public static void main(String[] args) {
    Vertx vertx = Vertx.vertx();
    vertx.deployVerticle(MyVerticle.class.getName());
}

or

public static void main(String[] args) {
    Vertx vertx = Vertx.vertx();
    vertx.deployVerticle(new MyVerticle());
}

EDIT: As suggested by Will, here is an example which takes the result into consideration and blocks the main thread until it succeeds:

BlockingQueue<AsyncResult<String>> q = new ArrayBlockingQueue<>(1);
Vertx.vertx().deployVerticle(new Application(), q::offer);
AsyncResult<String> result = q.take();
if (result.failed()) {
    throw new RuntimeException(result.cause());
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM