forked from vert-x3/vertx-examples
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Server.java
47 lines (40 loc) · 1.4 KB
/
Server.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
47
package io.vertx.example.jpms.grpc;
import io.grpc.examples.helloworld.HelloReply;
import io.grpc.examples.helloworld.HelloRequest;
import io.grpc.examples.helloworld.VertxGreeterGrpcServer;
import io.vertx.core.*;
import io.vertx.core.http.HttpServer;
import io.vertx.core.http.HttpServerOptions;
import io.vertx.core.net.JksOptions;
import io.vertx.grpc.server.GrpcServer;
public class Server extends VerticleBase {
public static void main(String[] args) {
Vertx vertx = Vertx.vertx();
vertx.deployVerticle(new Server())
.onFailure(Throwable::printStackTrace);
}
@Override
public Future<?> start() {
GrpcServer grpcServer = GrpcServer.server(vertx);
VertxGreeterGrpcServer.GreeterApi api = new VertxGreeterGrpcServer.GreeterApi() {
@Override
public Future<HelloReply> sayHello(HelloRequest request) {
return vertx.timer(200)
.map(v -> HelloReply
.newBuilder()
.setMessage("Hello " + request.getName())
.build());
}
};
api.bind_sayHello(grpcServer);
HttpServer server = vertx
.createHttpServer(
new HttpServerOptions()
.setUseAlpn(true)
.setKeyCertOptions(new JksOptions().setPath("server-keystore.jks").setPassword("wibble"))
.setSsl(false)
)
.requestHandler(grpcServer);
return server.listen(8080);
}
}