-
Notifications
You must be signed in to change notification settings - Fork 2k
Expand file tree
/
Copy pathClientWithStub.java
More file actions
43 lines (34 loc) · 1.3 KB
/
ClientWithStub.java
File metadata and controls
43 lines (34 loc) · 1.3 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
package io.vertx.example.grpc.ssl;
import io.grpc.examples.helloworld.GreeterGrpcClient;
import io.grpc.examples.helloworld.HelloRequest;
import io.vertx.core.Future;
import io.vertx.core.VerticleBase;
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.launcher.application.VertxApplication;
/**
* @author <a href="mailto:julien@julienviet.com">Julien Viet</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() {
HttpClientOptions options = new HttpClientOptions()
.setSsl(true)
.setUseAlpn(true)
.setTrustOptions(new JksOptions()
.setPath("tls/client-truststore.jks")
.setPassword("wibble"));
client = GrpcClient.client(vertx, options);
GreeterGrpcClient stub = GreeterGrpcClient.create(client, SocketAddress.inetSocketAddress(8080, "localhost"));
HelloRequest request = HelloRequest.newBuilder().setName("Julien").build();
return stub
.sayHello(request)
.onSuccess(res -> System.out.println("Succeeded " + res.getMessage()));
}
}