0

I'm learning by a mission-http-api-vertx coding my customizations on the scaffold generated by developers.redhat.com/launch using Eclipse Vert.x 3.4.2 .

I think the proposed approach is quite a classic but I do not understand what is the best practice to set VertxOptions in public class HttpApplication extends AbstractVerticle {

What I'm trying:

import io.vertx.core.AbstractVerticle;
import io.vertx.core.VertxOptions;

public class HttpApplication extends AbstractVerticle {
  protected final int DEFAULT_ADDRESS_RESOLUTION_TIMEOUT = 8000;
  @Override
  public void start(Future<Void> future) {
    //  [snip] Create a router object and routes
    // my custom options code start-here:[
    VertxOptions options = new VertxOptions()
                .setWarningExceptionTime(1500000000)
                .setAddressResolverOptions(new AddressResolverOptions()
                        .addServer("192.168.0.1")
                        .addServer("192.168.2.1")
                        .setMaxQueries(5)
                        .setCacheNegativeTimeToLive(0) // discard failed DNS lookup results immediately
                        .setCacheMaxTimeToLive(0) // support DNS based service resolution
                        .setRotateServers(true)
                        .setQueryTimeout(DEFAULT_ADDRESS_RESOLUTION_TIMEOUT));

    Vertx vertx = Vertx.vertx(options);
    // my custom options code:  end-here:]

    // Create the HTTP server and pass the "accept" method to the request handler.
    vertx
        .createHttpServer()
        .requestHandler(router::accept)
        .listen(

in particular I am very doubtful whether it is correct or not to get a vertx in Vertx vertx = Vertx.vertx(options); while the gerated code simply uses the Reference to the Vert.x instance that deployed this verticle provided by the abstract base class AbstractVerticle.

It's my approach safe? has it contraindications or risks breaking something? Is there a better practice to setup my custom VertxOptions in HttpApplication?

Franco Rondini
  • 10,841
  • 8
  • 51
  • 77
  • This is not correct, since you create another instance of VertX inside your verticle. How do you start VertX in the first place? – Alexey Soshin Jan 01 '18 at 17:08
  • You should use Vert.x instance provided as [field](http://vertx.io/docs/apidocs/io/vertx/rxjava/core/AbstractVerticle.html#vertx) of ```AbstractVerticle```. – Nolequen Jan 05 '18 at 20:33
  • @Nonequen by the Vert.x instance provided as field of AbstractVertiche is it possible to .setAddressResolverOptions adding a couple of server like I did in my question code sample ? – Franco Rondini Jan 08 '18 at 19:33
  • @Alexey I agree with you that it's not correct: I also asked to https://groups.google.com/forum/#!forum/vertx and , so far , the best option for me, is to implement my own `Launcher` that `extends VertxCommandLauncher implements VertxLifecycleHooks`. I launch my VertX as a fatjar and in the scaffold generated by scaffold generated by developers.redhat.com/launch basically there is only a public class HttpApplication extends AbstractVerticle – Franco Rondini Jan 08 '18 at 19:39

0 Answers0