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?
Deploying a Verticle First a Vertx instance is created. Second, the deployVerticle() method is called on the Vertx instance, with an instance of your verticle ( BasicVerticle in this example) as parameter. Vert. x will now deploy the verticle internally.
You can deploy a verticle using one of the deployVerticle method, specifying a verticle name or you can pass in a verticle instance you have already created yourself. Deploying Verticle instances is Java only. Verticle myVerticle = new MyVerticle(); vertx. deployVerticle(myVerticle);
A verticle is the fundamental processing unit in Vert. x. The role of a verticle is to encapsulate a technical functional unit for processing events such as exposing an HTTP API and responding to requests, providing a repository interface on top of a database, or issuing requests to a third-party system.
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());
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With