Deploying a service in verticle

22 views
Skip to first unread message

Charles Sam Dilip J

unread,
Apr 4, 2018, 3:51:05 PM4/4/18
to vert.x
Hi,

I want to deploy a verticle with service which lasts long, until I stop the jar with zookeeper as backend

I use the basic vertx to deploy the verticle.

// Verticle Snippet MyVerticl.java


 
ServiceDiscovery discovery = ServiceDiscovery.create(vertx,
       
new ServiceDiscoveryOptions().setBackendConfiguration(new JsonObject()
           
.put("connection", "localhost:2181")
           
.put("ephemeral", true)
           
.put("guaranteed", true)
           
.put("basePath", "/service/my-services")));
 
 
Record record = HttpEndpoint.createRecord("myhttpClient", "localhost", "8000", "/");


    discovery
.publish(record, ar -> {
     
if (ar.succeeded() && null != ar.result()) {
       
this.recordId = ar.result().getRegistration();
        fut
.complete();
     
} else {
        fut
.fail("Unable to start service");
     
}
   
});
    discovery
.close();


In the main I deploy my verticle as below

public static void main(String... args)  {
   
Vertx vertx = Vertx.vertx();
 vertx
.deployVerticle(new MyVerticle(), new DeploymentOptions(), ar -> {
 
if (ar.succeeded) {
   
// Succeeded codes
 
}
 
else {
   
// Failure Handler
 
}
 
});
}


But this cause the service to stop abruptly when the main snippet vertx stops, I am running on a single threaded event loop. I don't have clusters so I cannot setHa in Deployment option to pass the verticle to other vertx.

What would be the ideal way to deploy a standalone service verticle? 

Clement Escoffier

unread,
Apr 5, 2018, 3:12:52 AM4/5/18
to ve...@googlegroups.com
Hi,

don’t close the discovery instance before you registered the service. So move the discovery.close() call in the callback.

Clement

--
You received this message because you are subscribed to the Google Groups "vert.x" group.
To unsubscribe from this group and stop receiving emails from it, send an email to vertx+un...@googlegroups.com.
Visit this group at https://groups.google.com/group/vertx.
To view this discussion on the web, visit https://groups.google.com/d/msgid/vertx/6d323a8c-b447-4c47-b03e-467beb935a8b%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages