Reputation: 31
I have this vertx code :
DeploymentOptions deploymentOptions=new DeploymentOptions();
deploymentOptions.setInstances(2);
I want to know how to stop or kill one instance of the set instances.
Thanks.
Upvotes: 2
Views: 2457
Reputation: 156
As far as I know you cannot undeploy just one instance. You'll receive one deploymentId after the successful deployment of the verticles for which you provided the deploymentOptions.
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!");
}
});
So you just have the option to undeploy all the verticles at once for which you have received the deploymentId.
Upvotes: 0
Reputation: 17731
If you want to downscale vertices, you'll need to deploy a new set, then undeploy the old ones. This is a bit tricky, though:
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 */ });
In real application, you probably would like to first deploy new set of verticles, then in their completion handler undeploy the old ones. But for clarity I reversed this part.
Upvotes: 2