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?
Asked
Active
Viewed 6,914 times
1 Answers
11
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());
}

Alexander Torstling
- 18,552
- 7
- 62
- 74
-
It's always worth using the overloaded method that takes a handler with the result. Otherwise you won't know if your Verticle failed to start. – Will Apr 15 '16 at 10:02
-
@Will: Thanks, added an example which takes this into consideration. – Alexander Torstling Apr 15 '16 at 12:31
-
@AlexanderTorstling Can you be more clear about `result.cause()`? I can't see where it's coming from. – Mirza Brunjadze Aug 18 '17 at 15:38
-
@thisdotvoid good catch. `result` should be what `q.take()` returns, which is a Vertx AsyncResult. I'll edit. – Alexander Torstling Aug 21 '17 at 06:25
-
This answer leaves out the process of launching with the cmd args, such as launching in a cluster or specifying a conf. – Robin Coe Dec 11 '19 at 20:00