vertx-service-discovery icon indicating copy to clipboard operation
vertx-service-discovery copied to clipboard

How to get root from HttpClient which is published from ServiceDiscovery

Open nirajmchauhan opened this issue 7 years ago • 4 comments

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();
                        }
                    });

nirajmchauhan avatar Apr 17 '17 08:04 nirajmchauhan

Unfortunately, so far neither the HttpClient nor the WebClient allows setting a "root" url. You should be able to retrieve the root from the record if you use the getService methods.

cescoffier avatar Apr 18 '17 06:04 cescoffier

Any roadmap of getting this integrated with HTTPClient? Because for now the root is useless for HTTPEndPoint. Also it is a very useful feature to have

nirajmchauhan avatar Apr 18 '17 07:04 nirajmchauhan

@vietj WDYT ?

cescoffier avatar Apr 28 '17 19:04 cescoffier

Any update on this? Does vert.x 3.5 has this fixed? @vietj

nirajmchauhan avatar Aug 14 '17 15:08 nirajmchauhan