问题
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