Vert.x best way to to launch my apps (Vert.x command line vs Main method)

Viewed 501

I'm trying to decide which path i should follow when deploying my Verticles. I came to a conclusion that i should consider Vert.x as my runtime environment and not creating my own Vertx instance myself and start deploying my app from the main method. however i prefer having a main method in each app which gives me much control over my services doing service discovery and other stuff.

I can't find a piece of docs in Vertx talks about this point. or Pros and Cons. can someone please help me ?

Shell start:

cd /verticles # the location of the verticle jar
vertx run io.vertx.sample.RandomGeneratorVerticle
-cp /verticles/MY_VERTICLE.jar

Main method:

public static void main(String[] args) {
  Vertx vertx = Vertx.vertx();

  vertx.deployVerticle(
    new DatabaseVerticle(),
    new DeploymentOptions().setConfig(conf)
  )
}
2 Answers

There is another option: using the Vert.x Launcher class as your application entry point.

If you're developing with Java/Kotlin/Groovy it has the advantages of the CLI (you get support of options like -cluster, -instances, -conf) but you don't have to download/install it everywhere.

Using the Vert.x 3 CLI makes sense if you develop with JS/Ruby.

In Vert.x 4, JS and Ruby bindings are no longer generated, so using the CLI makes less sense although it is still supported.

In the long term (post Vert.x 5 so not tomorrow!) the CLI MAY not be supported.

In development cycle I'm using Gradle to do the starting.

The main advantage is that it has full IDE support, and you don't have to fiddle with start options every time you start your verticle.

You can also provide the default way of starting for your fellow developers.

In my apps I don't use static main() method as it kinda contradicts the Groovy way of living and adds code which does nothing more than double the CLI params which should belong to configuration rather than to code.

Related