我有这个vertx代码:
DeploymentOptions deploymentOptions=new DeploymentOptions();
deploymentOptions.setInstances(2);
我想知道如何停止或终止一组实例的实例。
感谢。
答案 0 :(得分:2)
如果要缩小顶点,则需要部署新集,然后取消部署旧集。但这有点棘手:
final String[] myId = {""};
vertx.deployVerticle("my.Verticle", new DeploymentOptions().setInstances(2), (h) -> {
if (h.succeeded()) {
// This is deployment ID for both. Store it in some holder, because Java
myId[0] = h.result();
}
else {
System.out.println("CAUSE " + h.cause());
}
});
// ...
// Here you decide to downscale
vertx.undeploy(myId[0], (h) -> { /* Deploy again with less instances */ });
在实际应用中,您可能希望首先部署新的Verticle集,然后在其完成处理程序中取消部署旧的Verticle。但为了清楚起见,我颠倒了这一部分。
答案 1 :(得分:0)
据我所知,你无法取消部署一个实例。在成功部署了您为其提供deploymentOptions的Verticle之后,您将收到一个deploymentId。
DeploymentOptions deploymentOptions = new DeploymentOptions();
deploymentOptions.setInstances(3);
vertx.deployVerticle("com.example.MyVerticle", deploymentOptions, res -> {
if (res.succeeded()) {
String deploymentId = res.result();
System.out.println("Deployment id is: " + deploymentId);
vertx.undeploy(deploymentId);
} else {
System.out.println("Deployment failed!");
}
});
因此,您可以选择一次取消部署已接收deployId的所有Verticle。