-
Notifications
You must be signed in to change notification settings - Fork 2.1k
/
ServerWithStub.java
43 lines (37 loc) · 1.3 KB
/
ServerWithStub.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.helloworld;
import io.grpc.examples.helloworld.HelloReply;
import io.grpc.examples.helloworld.HelloRequest;
import io.grpc.examples.helloworld.VertxGreeterGrpc;
import io.vertx.core.AbstractVerticle;
import io.vertx.core.Future;
import io.vertx.core.Launcher;
import io.vertx.grpc.server.GrpcServer;
import io.vertx.grpc.server.GrpcServiceBridge;
/**
* @author <a href="mailto:julien@julienviet.com">Julien Viet</a>
*/
public class ServerWithStub extends AbstractVerticle {
public static void main(String[] args) {
Launcher.executeCommand("run", ServerWithStub.class.getName());
}
@Override
public void start() {
VertxGreeterGrpc.GreeterVertxImplBase service = new VertxGreeterGrpc.GreeterVertxImplBase() {
@Override
public Future<HelloReply> sayHello(HelloRequest request) {
System.out.println("Hello " + request.getName());
return Future.succeededFuture(HelloReply.newBuilder().setMessage(request.getName()).build());
}
};
// Create the server
GrpcServer rpcServer = GrpcServer.server(vertx);
GrpcServiceBridge
.bridge(service)
.bind(rpcServer);
// start the server
vertx.createHttpServer().requestHandler(rpcServer).listen(8080)
.onFailure(cause -> {
cause.printStackTrace();
});
}
}