-
Notifications
You must be signed in to change notification settings - Fork 2k
Expand file tree
/
Copy pathClientWithStub.java
More file actions
53 lines (43 loc) · 1.59 KB
/
ClientWithStub.java
File metadata and controls
53 lines (43 loc) · 1.59 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
45
46
47
48
49
50
51
52
53
package io.vertx.example.grpc.consumer;
import io.vertx.core.Future;
import io.vertx.core.VerticleBase;
import io.vertx.core.net.SocketAddress;
import io.vertx.example.grpc.ConsumerServiceGrpcClient;
import io.vertx.example.grpc.Messages;
import io.vertx.grpc.client.GrpcClient;
import io.vertx.grpc.client.GrpcClientResponse;
import io.vertx.grpc.server.GrpcServerResponse;
import io.vertx.launcher.application.VertxApplication;
import java.nio.charset.StandardCharsets;
import java.util.function.Function;
import java.util.stream.Collectors;
/*
* @author <a href="mailto:plopes@redhat.com">Paulo Lopes</a>
*/
public class ClientWithStub extends VerticleBase {
public static void main(String[] args) {
VertxApplication.main(new String[]{ClientWithStub.class.getName()});
}
private GrpcClient client;
@Override
public Future<?> start() {
// Create the channel
client = GrpcClient.client(vertx);
// Get a stub to use for interacting with the remote service
ConsumerServiceGrpcClient stub = ConsumerServiceGrpcClient.create(client, SocketAddress.inetSocketAddress(8080, "localhost"));
// Make a request
Messages.StreamingOutputCallRequest request = Messages
.StreamingOutputCallRequest
.newBuilder()
.build();
// Call the remote service
return stub
.streamingOutputCall(request)
.compose(response -> {
response.handler(msg -> {
System.out.println(new String(msg.getPayload().toByteArray(), StandardCharsets.UTF_8));
});
return ((GrpcClientResponse)response).last().map("Response has ended.");
});
}
}