Partially “Rxifying” HttpServerVerticle

If you follow the guide in sequence, editing the code as you go, your HttpServerVerticle class is still using the callback-based API. Before you can use the RxJava API to execute asynchronous operations naturally, i.e. concurrently, you need to refactor HttpServerVerticle.

Import RxJava versions of Vert.x classes

  1. import io.vertx.guides.wiki.database.reactivex.WikiDatabaseService;
  2. import io.vertx.reactivex.core.AbstractVerticle;
  3. import io.vertx.reactivex.core.http.HttpServer;
  4. import io.vertx.reactivex.ext.auth.User;
  5. import io.vertx.reactivex.ext.auth.jdbc.JDBCAuth;
  6. import io.vertx.reactivex.ext.auth.jwt.JWTAuth;
  7. import io.vertx.reactivex.ext.jdbc.JDBCClient;
  8. import io.vertx.reactivex.ext.web.Router;
  9. import io.vertx.reactivex.ext.web.RoutingContext;
  10. import io.vertx.reactivex.ext.web.client.WebClient;
  11. import io.vertx.reactivex.ext.web.codec.BodyCodec;
  12. import io.vertx.reactivex.ext.web.handler.*;
  13. import io.vertx.reactivex.ext.web.sstore.LocalSessionStore;
  14. import io.vertx.reactivex.ext.web.templ.freemarker.FreeMarkerTemplateEngine;

Use delegate on a “Rxified” vertx instance

To call a method expecting a io.vertx.core.Vertx instance when you have a io.vertx.reactivex.core.Vertx one, call the getDelegate() method. Verticle’s start() method needs to be adjusted when creating an instance of WikiDatabaseService:

  1. @Override
  2. public void start(Promise<Void> promise) throws Exception {
  3. String wikiDbQueue = config().getString(CONFIG_WIKIDB_QUEUE, "wikidb.queue");
  4. dbService = io.vertx.guides.wiki.database.WikiDatabaseService.createProxy(vertx.getDelegate(), wikiDbQueue);