-
Notifications
You must be signed in to change notification settings - Fork 2k
Expand file tree
/
Copy pathClient.java
More file actions
44 lines (38 loc) · 1.49 KB
/
Client.java
File metadata and controls
44 lines (38 loc) · 1.49 KB
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
39
40
41
42
43
44
package io.vertx.example.grpc.deadline;
import io.grpc.examples.helloworld.GreeterGrpcClient;
import io.grpc.examples.helloworld.HelloReply;
import io.grpc.examples.helloworld.HelloRequest;
import io.vertx.core.Future;
import io.vertx.core.VerticleBase;
import io.vertx.core.net.SocketAddress;
import io.vertx.grpc.client.GrpcClient;
import io.vertx.grpc.client.GrpcClientOptions;
import io.vertx.grpc.common.GrpcReadStream;
import io.vertx.launcher.application.VertxApplication;
import java.util.concurrent.TimeUnit;
/**
* @author <a href="mailto:julien@julienviet.com">Julien Viet</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() throws Exception {
client = GrpcClient.client(vertx, new GrpcClientOptions()
.setTimeout(5)
.setTimeoutUnit(TimeUnit.SECONDS));
return client.request(SocketAddress.inetSocketAddress(8080, "localhost"), GreeterGrpcClient.SayHello)
.compose(request -> {
System.out.println("Sending a request that should timeout due to the server deadline");
request.end(HelloRequest.newBuilder().setName("Julien").build());
return request.response().compose(GrpcReadStream::last);
})
.map(HelloReply::getMessage)
.recover(err -> {
System.out.println("Timeout as expected");
return Future.succeededFuture("Expected timeout");
});
}
}