我正在学习Vertx.io和RxJava2。我想要实现的是以一种并行的方式完全部署一些verticles。这就是我想要做的:
...
public static void main(String[] args) {
log = LoggerFactory.getLogger(TheMainApp.class);
VertxOptions vertxOptions = new VertxOptions();
Vertx vertx = Vertx.vertx(vertxOptions);
try {
JsonObject config = getPropertyFile(args);
Flowable<Verticle> verticlesToDeploy = Flowable
.fromArray(new Verticle[] { new Verticle1(), new Verticle2(), new Verticle3(), ..., new VerticleN() });
verticlesToDeploy.flatMap(verticle -> {
return RxHelper.deployVerticle(vertx, verticle, new DeploymentOptions().setConfig(config))
.subscribeOn(Schedulers.io()).doOnError(err -> {
log.error(err.getCause());
throw new RuntimeException(err);
}).doAfterSuccess(ok -> {
log.info("Verticle {} deployed.", ok);
}).toFlowable();
});
} catch (CompositeException | IOException e) {
log.error("Deployment interrupted.");
System.out.println(e.getMessage());
vertx.close();
}
}
...但它不起作用。未部署任何verticle。我遗漏了什么?
发布于 2018-06-05 04:52:25
在.flatMap之后,您不会使用产生的可观察对象。由于代码是在main函数中调用的,因此可能需要添加.blockingSubscribe()
https://stackoverflow.com/questions/50688531
复制相似问题