-
Notifications
You must be signed in to change notification settings - Fork 2k
Expand file tree
/
Copy pathMainVerticle.java
More file actions
27 lines (24 loc) · 868 Bytes
/
MainVerticle.java
File metadata and controls
27 lines (24 loc) · 868 Bytes
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
package io.vertx.example;
import io.grpc.ManagedChannel;
import io.grpc.examples.helloworld.GreeterGrpc;
import io.grpc.examples.helloworld.HelloRequest;
import io.vertx.core.AbstractVerticle;
import io.vertx.grpc.VertxChannelBuilder;
public class MainVerticle extends AbstractVerticle {
@Override
public void start() {
ManagedChannel channel = VertxChannelBuilder
.forAddress(vertx, "localhost", 50051)
.usePlaintext(true)
.build();
GreeterGrpc.GreeterVertxStub stub = GreeterGrpc.newVertxStub(channel);
HelloRequest request = HelloRequest.newBuilder().setName("Paulo").build();
stub.sayHello(request, asyncResponse -> {
if (asyncResponse.succeeded()) {
System.out.println("Succeeded " + asyncResponse.result().getMessage());
} else {
asyncResponse.cause().printStackTrace();
}
});
}
}