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
import io.vertx.guides.wiki.database.reactivex.WikiDatabaseService;
import io.vertx.reactivex.core.AbstractVerticle;
import io.vertx.reactivex.core.http.HttpServer;
import io.vertx.reactivex.ext.auth.User;
import io.vertx.reactivex.ext.auth.jdbc.JDBCAuth;
import io.vertx.reactivex.ext.auth.jwt.JWTAuth;
import io.vertx.reactivex.ext.jdbc.JDBCClient;
import io.vertx.reactivex.ext.web.Router;
import io.vertx.reactivex.ext.web.RoutingContext;
import io.vertx.reactivex.ext.web.client.WebClient;
import io.vertx.reactivex.ext.web.codec.BodyCodec;
import io.vertx.reactivex.ext.web.handler.*;
import io.vertx.reactivex.ext.web.sstore.LocalSessionStore;
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
:
@Override
public void start(Promise<Void> promise) throws Exception {
String wikiDbQueue = config().getString(CONFIG_WIKIDB_QUEUE, "wikidb.queue");
dbService = io.vertx.guides.wiki.database.WikiDatabaseService.createProxy(vertx.getDelegate(), wikiDbQueue);