eclipse-vertx / vert.x

Vert.x is a tool-kit for building reactive applications on the JVM
http://vertx.io
Other
14.26k stars 2.07k forks source link

How to get root from HttpClient which is published from ServiceDiscovery #1947

Closed nirajmchauhan closed 7 years ago

nirajmchauhan commented 7 years ago

When we publish an HTTPEndPoint record, we pass an argument named as root. This root is not accessed when we getRecord.

Publishing record:

ServiceDiscovery discovery = ServiceDiscovery.create(vertx, new ServiceDiscoveryOptions()
        .setBackendConfiguration(
                new JsonObject()
                        .put("host", "127.0.0.1")
                        .put("key", "record")
        ));
discovery.publish(HttpEndpoint.createRecord(
        "users",
        "localhost", HTTP_PORT,
        "/v1/api/"),
        ar -> {
            if (ar.succeeded()) {
                System.out.println("Tweets API published");
            } else {
                System.out.println("Unable to publish the Tweets API: " +
                        ar.cause().getMessage());
            }
        });

Getting Record:

HttpEndpoint.getClient(serviceDiscovery, new JsonObject().put("name", "users"), record -> {
                        if(!record.failed()){
                            HttpClient client = record.result();
                            client.get("/v1/api/users", response ->{
                                response.bodyHandler(body -> operation.complete(body.toString()));
                            }).exceptionHandler(operation::fail)
                                    .end();
                        }
                    });
vietj commented 7 years ago

can you move this issue to this repository instead https://github.com/vert-x3/vertx-service-discovery ? thanks

nirajmchauhan commented 7 years ago

Done.