-
Notifications
You must be signed in to change notification settings - Fork 2.1k
/
Copy pathClient.java
38 lines (31 loc) · 1.14 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.grpc.empty;
import io.vertx.core.Future;
import io.vertx.core.VerticleBase;
import io.vertx.core.net.SocketAddress;
import io.vertx.example.grpc.EmptyProtos;
import io.vertx.example.grpc.VertxEmptyPingPongServiceGrpcClient;
import io.vertx.grpc.client.GrpcClient;
import io.vertx.grpc.common.GrpcReadStream;
import io.vertx.launcher.application.VertxApplication;
/*
* @author <a href="mailto:[email protected]">Paulo Lopes</a>
*/
public class Client extends VerticleBase {
public static void main(String[] args) {
VertxApplication.main(new String[]{Client.class.getName()});
}
private GrpcClient client;
@Override
public Future<?> start() {
// Create the channel
client = GrpcClient.client(vertx);
// Call the remote service
return client.request(SocketAddress.inetSocketAddress(8080, "localhost"), VertxEmptyPingPongServiceGrpcClient.EmptyCall)
.compose(request -> {
request.end(EmptyProtos.Empty.newBuilder().build());
return request.response().compose(GrpcReadStream::last);
}).onSuccess(empty -> {
System.out.println("Got the server response.");
});
}
}