-
Notifications
You must be signed in to change notification settings - Fork 2.1k
/
Client.java
38 lines (32 loc) · 1.1 KB
/
Client.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
package io.vertx.example.rxjava3.web.client.zip;
import io.reactivex.rxjava3.core.Single;
import io.vertx.core.Launcher;
import io.vertx.core.json.JsonObject;
import io.vertx.rxjava3.core.AbstractVerticle;
import io.vertx.rxjava3.ext.web.client.WebClient;
import io.vertx.rxjava3.ext.web.codec.BodyCodec;
/*
* @author <a href="mailto:julien@julienviet.com">Julien Viet</a>
*/
public class Client extends AbstractVerticle {
public static void main(String[] args) {
Launcher.executeCommand("run", Client.class.getName());
}
@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();
});
}
}