use of io.vertx.rxjava.ext.web.client.WebClient in project vertx-examples by vert-x3.
the class Client method start.
@Override
public void start() throws Exception {
WebClient client = WebClient.create(vertx);
Single<HttpResponse<Data>> request = client.get(8080, "localhost", "/").as(BodyCodec.json(Data.class)).rxSend();
// Fire the request
request.subscribe(resp -> System.out.println("Server content " + resp.body().message));
// Again
request.subscribe(resp -> System.out.println("Server content " + resp.body().message));
// And again
request.subscribe(resp -> System.out.println("Server content " + resp.body().message));
}
use of io.vertx.rxjava.ext.web.client.WebClient in project vertx-openshift-it by cescoffier.
the class GatewayVerticle method start.
@Override
public void start() throws Exception {
dnsClient = vertx.createHttpClient(new HttpClientOptions().setDefaultHost(ENDPOINT_NAME).setDefaultPort(8080).setKeepAlive(false));
dnsWeb = WebClient.create(vertx, new WebClientOptions().setDefaultHost(ENDPOINT_NAME).setDefaultPort(8080).setKeepAlive(false));
dnsDatabase = JDBCClient.createShared(vertx, new JsonObject().put("url", "jdbc:postgresql://my-database:5432/my_data").put("driver_class", "org.postgresql.Driver").put("user", "luke").put("password", "secret"));
Router router = Router.router(vertx);
router.get("/health").handler(rc -> rc.response().end("OK"));
router.get("/services/http").handler(this::invokeHttpService);
router.get("/services/web").handler(this::invokeWebService);
router.get("/services/db").handler(this::checkDb);
router.get("/dns/http").handler(this::invokeHttpServiceWithDns);
router.get("/dns/web").handler(this::invokeWebServiceWithDns);
router.get("/dns/db").handler(this::checkDbWithDns);
router.get("/ref/http").handler(this::invokeHttpServiceWithRef);
router.get("/ref/web").handler(this::invokeWebServiceWithRef);
router.put("/webclient").handler(this::webclient);
ServiceDiscovery.create(vertx, discovery -> {
this.discovery = discovery;
Single<WebClient> svc1 = HttpEndpoint.rxGetWebClient(discovery, svc -> svc.getName().equals(ENDPOINT_NAME), new JsonObject().put("keepAlive", false));
Single<HttpClient> svc2 = HttpEndpoint.rxGetClient(discovery, svc -> svc.getName().equals(ENDPOINT_NAME), new JsonObject().put("keepAlive", false));
Single<JDBCClient> svc3 = JDBCDataSource.rxGetJDBCClient(discovery, svc -> svc.getName().equals("my-database"), new JsonObject().put("url", "jdbc:postgresql://my-database:5432/my_data").put("driver_class", "org.postgresql.Driver").put("user", "luke").put("password", "secret"));
Single.zip(svc1, svc2, svc3, (wc, hc, db) -> {
this.web = wc;
this.client = hc;
this.database = db;
return vertx.createHttpServer().requestHandler(router::accept).listen(8080);
}).subscribe();
});
}
use of io.vertx.rxjava.ext.web.client.WebClient in project vertx-examples by vert-x3.
the class Client method start.
@Override
public void start() throws Exception {
WebClient client = WebClient.create(vertx);
Single<HttpResponse<String>> request = client.get(8080, "localhost", "/").as(BodyCodec.string()).rxSend();
// Fire the request
request.subscribe(resp -> System.out.println("Server content " + resp.body()));
// Again
request.subscribe(resp -> System.out.println("Server content " + resp.body()));
// And again
request.subscribe(resp -> System.out.println("Server content " + resp.body()));
}
use of io.vertx.rxjava.ext.web.client.WebClient in project vertx-examples by vert-x3.
the class Client method start.
@Override
public void start() throws Exception {
// Create two requests
WebClient client = WebClient.create(vertx);
Single<JsonObject> request = client.get(8080, "localhost", "/").as(BodyCodec.jsonObject()).rxSend().map(resp -> resp.body());
// Combine the responses with the zip into a single response
request.zipWith(request, (b1, b2) -> new JsonObject().put("req1", b1).put("req2", b2)).subscribe(json -> {
System.out.println("Got combined result " + json);
}, err -> {
err.printStackTrace();
});
}
Aggregations