Deploying verticles in order
To finalize the MainVerticle
refactoring, we must make sure the deployment operations get triggered and happen in order:
dbVerticleDeployment
.flatMap(id -> { (1)
Single<String> httpVerticleDeployment = vertx.rxDeployVerticle(
"io.vertx.guides.wiki.http.HttpServerVerticle",
new DeploymentOptions().setInstances(2));
return httpVerticleDeployment;
})
.flatMap(id -> vertx.rxDeployVerticle("io.vertx.guides.wiki.http.AuthInitializerVerticle")) (2)
.subscribe(id -> promise.complete(), promise::fail); (3)
The
flatMap
operator applies the function to the result ofdbVerticleDeployment
. Here it schedules the deployment of theHttpServerVerticle
.We use the shorter lambda form here.
Operations start when subscribing. On success or on error, the
MainVerticle
start future is either completed or failed.