I have a custom client object that I am instantiating in the main() method and need to pass it to all the verticle instances that I am going to deploy. Here is what I have tried -
1.)
private static Connection connection;
.
.
.
//method to initialise client
initialiseClient();
final DeploymentOptions deployOpts = new DeploymentOptions().setInstances(num_instances);
vertx.deployVerticle(new MyVerticle(connection), deployOpts, ar -> {
if (ar.succeeded()) {
startFuture.complete();
} else {
startFuture.fail(ar.cause());
}
});
In this case I am getting the following error because the verticle instance has already been created.
Can't specify > 1 instances for already created verticle
2.)
JsonObject object = new JsonObject().put("connection-object", connection);
final DeploymentOptions deployOpts = new DeploymentOptions().setInstances(num_instances);
vertx.deployVerticle(MyVerticle.class.getName(), deployOpts, ar -> {
if (ar.succeeded()) {
startFuture.complete();
} else {
startFuture.fail(ar.cause());
}
});
In this case I get the error
java.lang.IllegalStateException: Illegal type in JsonObject: class com.abc.def.Connection
So my question is, is there any way to pass a custom class object while deploying multiple instances of a verticle?