-
Notifications
You must be signed in to change notification settings - Fork 2.1k
/
ClientWithStub.java
43 lines (38 loc) · 1.53 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
package io.vertx.example.grpc.ssl;
import io.grpc.examples.helloworld.HelloRequest;
import io.grpc.examples.helloworld.VertxGreeterGrpcClient;
import io.vertx.core.AbstractVerticle;
import io.vertx.core.Launcher;
import io.vertx.core.http.HttpClientOptions;
import io.vertx.core.net.JksOptions;
import io.vertx.core.net.SocketAddress;
import io.vertx.grpc.client.GrpcClient;
import io.vertx.grpc.client.GrpcClientChannel;
/**
* @author <a href="mailto:[email protected]">Julien Viet</a>
*/
public class ClientWithStub extends AbstractVerticle {
public static void main(String[] args) {
Launcher.executeCommand("run", ClientWithStub.class.getName());
}
@Override
public void start() {
HttpClientOptions options = new HttpClientOptions()
.setSsl(true)
.setUseAlpn(true)
.setTrustOptions(new JksOptions()
.setPath("tls/client-truststore.jks")
.setPassword("wibble"));
GrpcClient client = GrpcClient.client(vertx, options);
GrpcClientChannel channel = new GrpcClientChannel(client, SocketAddress.inetSocketAddress(8080, "localhost"));
VertxGreeterGrpcClient stub = new VertxGreeterGrpcClient(client, SocketAddress.inetSocketAddress(8080, "localhost"));
HelloRequest request = HelloRequest.newBuilder().setName("Julien").build();
stub.sayHello(request).onComplete(asyncResponse -> {
if (asyncResponse.succeeded()) {
System.out.println("Succeeded " + asyncResponse.result().getMessage());
} else {
asyncResponse.cause().printStackTrace();
}
});
}
}