-
Notifications
You must be signed in to change notification settings - Fork 2.1k
/
ServiceConsumerVerticle.java
30 lines (23 loc) · 1.02 KB
/
ServiceConsumerVerticle.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
package io.vertx.example.reactivex.services.serviceproxy;
import io.reactivex.Single;
import io.vertx.core.Launcher;
import io.vertx.core.json.JsonObject;
import io.vertx.reactivex.core.AbstractVerticle;
public class ServiceConsumerVerticle extends AbstractVerticle {
// In order to use Rx-ified methods, you need to declare the service in Rx-style.
io.vertx.example.reactivex.services.serviceproxy.reactivex.SomeDatabaseService someDatabaseService;
public static void main(String[] args) {
Launcher.executeCommand("run", ServiceConsumerVerticle.class.getName(), "-cluster");
}
@Override
public void start() throws Exception {
someDatabaseService = SomeDatabaseService.createProxy(vertx.getDelegate(), "proxy.address");
int id = 1;
// Now you can use your Rx-ified methods.
Single<JsonObject> single = someDatabaseService.rxGetDataById(id);
single.subscribe(
jsonObject -> System.out.println(jsonObject.encodePrettily()),
throwable -> System.out.println(throwable.getMessage())
);
}
}