-
Notifications
You must be signed in to change notification settings - Fork 2.1k
/
ClientWithStub.java
46 lines (37 loc) · 1.36 KB
/
ClientWithStub.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
39
40
41
42
43
44
45
46
package io.vertx.example.grpc.consumer;
import io.vertx.core.AbstractVerticle;
import io.vertx.core.Launcher;
import io.vertx.core.net.SocketAddress;
import io.vertx.example.grpc.Messages;
import io.vertx.example.grpc.VertxConsumerServiceGrpcClient;
import io.vertx.grpc.client.GrpcClient;
import java.nio.charset.StandardCharsets;
/*
* @author <a href="mailto:[email protected]">Paulo Lopes</a>
*/
public class ClientWithStub extends AbstractVerticle {
public static void main(String[] args) {
Launcher.executeCommand("run", ClientWithStub.class.getName());
}
@Override
public void start() {
// Create the channel
GrpcClient client = GrpcClient.client(vertx);
// Get a stub to use for interacting with the remote service
VertxConsumerServiceGrpcClient stub = new VertxConsumerServiceGrpcClient(client, SocketAddress.inetSocketAddress(8080, "localhost"));
// Make a request
Messages.StreamingOutputCallRequest request = Messages
.StreamingOutputCallRequest
.newBuilder()
.build();
// Call the remote service
stub.streamingOutputCall(request)
.onSuccess(response -> {
response.handler(msg -> {
System.out.println(new String(msg.getPayload().toByteArray(), StandardCharsets.UTF_8));
}).endHandler(v -> {
System.out.println("Response has ended.");
});
});
}
}