Search in sources :

Example 6 with HttpClientRequest

use of io.vertx.reactivex.core.http.HttpClientRequest in project vertx-examples by vert-x3.

the class Client method start.

@Override
public void start() throws Exception {
    HttpClient client = vertx.createHttpClient();
    // Create two requests
    HttpClientRequest req1 = client.request(HttpMethod.GET, 8080, "localhost", "/");
    HttpClientRequest req2 = client.request(HttpMethod.GET, 8080, "localhost", "/");
    // Turn the requests responses into Flowable<JsonObject>
    Flowable<JsonObject> obs1 = req1.toFlowable().flatMap(HttpClientResponse::toFlowable).map(buf -> new JsonObject(buf.toString("UTF-8")));
    Flowable<JsonObject> obs2 = req2.toFlowable().flatMap(HttpClientResponse::toFlowable).map(buf -> new JsonObject(buf.toString("UTF-8")));
    // Combine the responses with the zip into a single response
    obs1.zipWith(obs2, (b1, b2) -> new JsonObject().put("req1", b1).put("req2", b2)).subscribe(json -> {
        System.out.println("Got combined result " + json);
    }, Throwable::printStackTrace);
    req1.end();
    req2.end();
}
Also used : HttpClientRequest(io.vertx.reactivex.core.http.HttpClientRequest) Flowable(io.reactivex.Flowable) HttpMethod(io.vertx.core.http.HttpMethod) JsonObject(io.vertx.core.json.JsonObject) HttpClient(io.vertx.reactivex.core.http.HttpClient) AbstractVerticle(io.vertx.reactivex.core.AbstractVerticle) Runner(io.vertx.example.util.Runner) HttpClientResponse(io.vertx.reactivex.core.http.HttpClientResponse) HttpClientRequest(io.vertx.reactivex.core.http.HttpClientRequest) HttpClient(io.vertx.reactivex.core.http.HttpClient) JsonObject(io.vertx.core.json.JsonObject)

Example 7 with HttpClientRequest

use of io.vertx.reactivex.core.http.HttpClientRequest in project knotx by Cognifide.

the class KnotxServerRoutingTest method request.

private static Observable<HttpClientResponse> request(HttpClient client, HttpMethod method, int port, String domain, String uri, Action1<HttpClientRequest> requestBuilder) {
    return Observable.unsafeCreate(subscriber -> {
        HttpClientRequest req = client.request(method, port, domain, uri);
        Observable<HttpClientResponse> resp = req.toObservable();
        resp.subscribe(subscriber);
        requestBuilder.call(req);
        req.end();
    });
}
Also used : HttpClientRequest(io.vertx.reactivex.core.http.HttpClientRequest) HttpClientResponse(io.vertx.reactivex.core.http.HttpClientResponse)

Aggregations

HttpClientRequest (io.vertx.reactivex.core.http.HttpClientRequest)7 HttpClientResponse (io.vertx.reactivex.core.http.HttpClientResponse)5 HttpMethod (io.vertx.core.http.HttpMethod)4 Runner (io.vertx.example.util.Runner)4 AbstractVerticle (io.vertx.reactivex.core.AbstractVerticle)4 HttpClient (io.vertx.reactivex.core.http.HttpClient)4 Flowable (io.reactivex.Flowable)2 JsonObject (io.vertx.core.json.JsonObject)1 Buffer (io.vertx.reactivex.core.buffer.Buffer)1