vertx-service-discovery
vertx-service-discovery copied to clipboard
How to get root from HttpClient which is published from ServiceDiscovery
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();
}
});
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.
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
@vietj WDYT ?
Any update on this? Does vert.x 3.5 has this fixed? @vietj