8

如何从 main 方法启动 Verx 3 Verticle?我已经弄清楚如何从单元测试开始它,入门指南解释了如何构建一个胖罐子。但是,为了调试、分析等目的,我如何简单地从主要方法开始呢?

4

1 回答 1

11

简单地做

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

或者

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

编辑:正如 Will 所建议的,这是一个将结果考虑在内并阻塞主线程直到成功的示例:

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());
}
于 2016-03-31T14:53:45.527 回答