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

☆樱花仙子☆ 提交于 2019-12-08 19:28:39

问题


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?


回答1:


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());
}


来源:https://stackoverflow.com/questions/36336880/how-do-i-start-a-vertx-3-verticle-from-a-main-method

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!