通過Vert.x應用程序的日誌來看,我取消部署verticles時(這是相同的例外所有3)發現以下異常:Vert.x取消部署verticle拋出IllegalStateException異常未知部署
Failed to undeploy netsci.graphservice.verticles.CommandVerticle
Failed to undeploy netsci.graphservice.verticles.QueryVerticle
Failed to undeploy netsci.graphservice.verticles.EventVerticle
java.lang.IllegalStateException: Unknown deployment
at io.vertx.core.impl.DeploymentManager.undeployVerticle(DeploymentManager.java:203)
at io.vertx.core.impl.VertxImpl.undeploy(VertxImpl.java:616)
at microservice.MasterMicroserviceVerticle.undeploySupportingVerticle(MasterMicroserviceVerticle.java:462)
at java.util.stream.ReferencePipeline$3$1.accept(ReferencePipeline.java:193)
at java.util.HashMap$KeySpliterator.forEachRemaining(HashMap.java:1548)
at java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:481)
at java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:471)
at java.util.stream.ReduceOps$ReduceOp.evaluateSequential(ReduceOps.java:708)
at java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:234)
at java.util.stream.ReferencePipeline.collect(ReferencePipeline.java:499)
at microservice.MasterMicroserviceVerticle.stopSupportingVerticles(MasterMicroserviceVerticle.java:433)
at microservice.MasterMicroserviceVerticle.lambda$stop$14(MasterMicroserviceVerticle.java:383)
at io.vertx.core.Future.lambda$compose$1(Future.java:270)
at io.vertx.core.impl.FutureImpl.tryComplete(FutureImpl.java:126)
at io.vertx.core.impl.FutureImpl.complete(FutureImpl.java:88)
at io.vertx.core.impl.FutureImpl.handle(FutureImpl.java:152)
at io.vertx.core.impl.FutureImpl.handle(FutureImpl.java:23)
at io.vertx.core.impl.FutureImpl.setHandler(FutureImpl.java:81)
at io.vertx.core.Future.lambda$compose$1(Future.java:275)
at io.vertx.core.impl.FutureImpl.tryComplete(FutureImpl.java:126)
at io.vertx.core.impl.FutureImpl.complete(FutureImpl.java:88)
at io.vertx.core.impl.FutureImpl.handle(FutureImpl.java:152)
at io.vertx.core.impl.FutureImpl.handle(FutureImpl.java:23)
at io.vertx.core.impl.FutureImpl.tryComplete(FutureImpl.java:126)
at io.vertx.core.impl.FutureImpl.tryComplete(FutureImpl.java:133)
at io.vertx.core.impl.FutureImpl.complete(FutureImpl.java:95)
at microservice.MasterMicroserviceVerticle.lambda$null$11(MasterMicroserviceVerticle.java:363)
at microservice.messaging.impl.BufferKafkaProducerService.lambda$shutdown$2(BufferKafkaProducerService.java:97)
at io.vertx.core.impl.FutureImpl.setHandler(FutureImpl.java:81)
at io.vertx.core.impl.ContextImpl.lambda$null$0(ContextImpl.java:287)
at io.vertx.core.impl.ContextImpl.lambda$wrapTask$2(ContextImpl.java:337)
at io.netty.util.concurrent.AbstractEventExecutor.safeExecute(AbstractEventExecutor.java:163)
at io.netty.util.concurrent.SingleThreadEventExecutor.runAllTasks(SingleThreadEventExecutor.java:403)
at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:445)
at io.netty.util.concurrent.SingleThreadEventExecutor$5.run(SingleThreadEventExecutor.java:858)
at java.lang.Thread.run(Thread.java:748)
然而,他們都部署有一個配置ID:
Deployed: 213f1978-a595-4af1-8129-29de872e9907
Deployed: e46839f1-2dd2-4cce-9e12-66e09677b97a
Deployed: 8fdfd492-e005-4503-875e-13d73c633b2c
部署的ID存儲在同步映射,與verticle類作爲鍵和部署的id的值。查詢時,就說明他們被正確地存儲:
class netsci.graphservice.verticles.QueryVerticle: e46839f1-2dd2-4cce-9e12-66e09677b97a
class netsci.graphservice.verticles.CommandVerticle: 8fdfd492-e005-4503-875e-13d73c633b2c
class netsci.graphservice.verticles.EventVerticle: 213f1978-a595-4af1-8129-29de872e9907
此前呼籲endeploy,如果我檢查哪個verticle正在取消部署,我得到可以看到,有效的配置ID被傳遞到調用取消部署:
Undeploying: e46839f1-2dd2-4cce-9e12-66e09677b97a
Undeploying: 8fdfd492-e005-4503-875e-13d73c633b2c
Undeploying: 213f1978-a595-4af1-8129-29de872e9907
這裏是代碼的相關位:
public abstract class MasterMicroserviceVerticle extends MicroserviceVerticle {
private final Map<Class, String> supportingVerticles =
Collections.synchronizedMap(new HashMap<Class, String>());
...
private Future<Void> deploySupportingVerticle(Class verticle) {
Future<Void> future = Future.future();
vertx.deployVerticle(
verticle.getName(),
new DeploymentOptions().setConfig(config()),
asyncResult -> {
if (asyncResult.succeeded()) {
// Assign deployment ID to verticle map.
String depId = asyncResult.result();
System.out.println();
System.out.println();
System.out.println(depId);
System.out.println();
System.out.println();
supportingVerticles.put(verticle, depId);
healthStatusService.setHealth(verticle.getName(), HealthStatus.PASSING);
logger.info("Deployed {}", verticle.getName());
future.complete();
} else {
healthStatusService.setHealth(verticle.getName(), HealthStatus.FAILING);
logger.error("Failed to deploy {}", verticle.getName(), asyncResult.cause());
future.fail(asyncResult.cause());
}
});
return future;
}
...
@Override
public void stop(Future<Void> stopFuture) throws Exception {
System.out.println();
System.out.println();
System.out.println();
System.out.println();
System.out.println();
for (Class c : supportingVerticles.keySet()) {
System.out.println(c + ": " + supportingVerticles.get(c));
}
System.out.println();
System.out.println();
System.out.println();
System.out.println();
System.out.println();
...
return mongoFuture;
}).compose(handler -> {
Future<Void> verticlesFuture = Future.future();
stopSupportingVerticles(verticlesFuture.completer());
return verticlesFuture;
}).compose(handler ->
logger.info("Undeployed service");
stopFuture.completer();
}, stopFuture);
}
protected void stopSupportingVerticles(Handler<AsyncResult<Void>> handler) {
List<Future> undeployable = supportingVerticles
.keySet()
.stream()
.map(this::undeploySupportingVerticle)
.collect(Collectors.toList());
CompositeFuture.all(undeployable)
.setHandler(asyncResult -> {
if (asyncResult.succeeded()) {
handler.handle(Future.succeededFuture());
} else {
handler.handle(Future.failedFuture(asyncResult.cause()));
}
});
}
private Future<Void> undeploySupportingVerticle(Class verticle) {
Future<Void> future = Future.future();
System.out.println();
System.out.println();
System.out.println("Undeploying: " + supportingVerticles.get(verticle));
System.out.println();
System.out.println();
vertx.undeploy(supportingVerticles.get(verticle), asyncResult -> {
healthStatusService.setHealth(verticle.getName(), HealthStatus.FAILING);
if (asyncResult.succeeded()) {
logger.info("Undeployed {}", verticle.getName());
future.complete();
} else {
logger.error("Failed to undeploy {}", verticle.getName(), asyncResult.cause());
future.fail(asyncResult.cause());
}
});
return future;
}
}
請原諒所有System.out.println()
的,我已經拋出他們有幫我拿一個BETT呃知道發生了什麼,應該在日誌中記錄這些信息。但就目前而言,我只是感謝所有幫助理解Vert.x爲什麼說部署是未知的?
如果我想控制停止序列以確保在其他Verticle中的任何剩餘工作在關閉之前完成,這就是爲什麼我重寫'stop()'並調用undeploy。我不會調用'super.stop()',那麼如何防止Vert.x自動取消部署? – amb85
我不確定您是否可以控制取消部署順序。如果你看看'io.vertx.core.impl.DeploymentManager.DeploymentImpl#doUndeploy',你可以看到所有的子Verticle都會在它們的父代之前自動解除部署。 也許你可以檢查你的孩子verticle,如果還有一些工作要做,並且只有在剩下的工作完成後才能完成'stopFuture'。 – michalsamek
直到工作完成,我才完成停止未來。我曾認爲通過調用undeploy()會啓動停止。現在,我更好地理解爲什麼它會以這種方式行事,我可以重新思考我的整潔關閉策略。謝謝。 – amb85