如何从主方法启动 Vertx 3 Verticle? [英] How do I start a Vertx 3 Verticle from a main method?

查看:23
本文介绍了如何从主方法启动 Vertx 3 Verticle?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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?

推荐答案

简单做

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 所建议的,这是一个考虑结果并阻塞主线程直到它成功的示例:

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

这篇关于如何从主方法启动 Vertx 3 Verticle?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆