forked from vert-x3/vertx-examples
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Client.java
40 lines (36 loc) · 1.28 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
39
40
package io.vertx.example.grpc.ssl;
import io.grpc.ManagedChannel;
import io.grpc.examples.helloworld.HelloRequest;
import io.grpc.examples.helloworld.VertxGreeterGrpc;
import io.vertx.core.AbstractVerticle;
import io.vertx.core.net.JksOptions;
import io.vertx.example.grpc.util.Runner;
import io.vertx.grpc.VertxChannelBuilder;
/**
* @author <a href="mailto:[email protected]">Julien Viet</a>
*/
public class Client extends AbstractVerticle {
public static void main(String[] args) {
Runner.runExample(Client.class);
}
@Override
public void start() {
ManagedChannel channel = VertxChannelBuilder
.forAddress(vertx, "localhost", 8080)
.useSsl(options -> options.setSsl(true)
.setUseAlpn(true)
.setTrustStoreOptions(new JksOptions()
.setPath("tls/client-truststore.jks")
.setPassword("wibble")))
.build();
VertxGreeterGrpc.GreeterVertxStub stub = VertxGreeterGrpc.newVertxStub(channel);
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();
}
});
}
}