Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I start a Vertx 3 Verticle from a main method?

Tags:

java

vertx3

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?

like image 684
Alexander Torstling Avatar asked Mar 31 '16 14:03

Alexander Torstling


People also ask

How do you run a verticle on a Vertx?

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.

How do you deploy a verticle?

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

What is a vertical in Vertx?

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.


1 Answers

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());
}
like image 192
Alexander Torstling Avatar answered Oct 27 '22 17:10

Alexander Torstling