use of io.vertx.grpc.VertxServer in project vertx-openshift-it by cescoffier.
the class HelloGrpcVerticle method start.
@Override
public void start() throws Exception {
VertxServer server = VertxServerBuilder.forPort(vertx, 8082).useSsl(options -> options.setSsl(true).setUseAlpn(true).setKeyStoreOptions(new JksOptions().setPath("tls/server-keystore.jks").setPassword("wibble"))).addService(new GreeterGrpc.GreeterVertxImplBase() {
@Override
public void sayHello(HelloRequest request, Future<HelloReply> future) {
System.out.println("Hello " + request.getName());
future.complete(HelloReply.newBuilder().setMessage("Hello " + request.getName()).build());
}
}).build();
server.start(ar -> {
if (ar.succeeded()) {
System.out.println("gRPC service started");
} else {
System.out.println("Could not start server " + ar.cause().getMessage());
}
});
}
use of io.vertx.grpc.VertxServer in project vertx-examples by vert-x3.
the class Server method start.
@Override
public void start() throws Exception {
// The rcp service
ConsumerServiceGrpc.ConsumerServiceVertxImplBase service = new ConsumerServiceGrpc.ConsumerServiceVertxImplBase() {
@Override
public void streamingOutputCall(Messages.StreamingOutputCallRequest request, GrpcWriteStream<Messages.StreamingOutputCallResponse> response) {
final AtomicInteger counter = new AtomicInteger();
vertx.setPeriodic(1000L, t -> {
response.write(Messages.StreamingOutputCallResponse.newBuilder().setPayload(Messages.Payload.newBuilder().setTypeValue(PayloadType.COMPRESSABLE.getNumber()).setBody(ByteString.copyFrom(String.valueOf(counter.incrementAndGet()), Charset.forName("UTF-8")))).build());
});
}
};
// Create the server
VertxServer rpcServer = VertxServerBuilder.forPort(vertx, 8080).addService(service).build();
// start the server
rpcServer.start(ar -> {
if (ar.failed()) {
ar.cause().printStackTrace();
}
});
}
use of io.vertx.grpc.VertxServer in project vertx-examples by vert-x3.
the class Server method start.
@Override
public void start() throws Exception {
// The rcp service
ConversationalServiceGrpc.ConversationalServiceVertxImplBase service = new ConversationalServiceGrpc.ConversationalServiceVertxImplBase() {
@Override
public void fullDuplexCall(GrpcBidiExchange<Messages.StreamingOutputCallRequest, Messages.StreamingOutputCallResponse> exchange) {
exchange.handler(req -> {
System.out.println("Server: received request");
vertx.setTimer(500L, t -> {
exchange.write(Messages.StreamingOutputCallResponse.newBuilder().build());
});
});
}
};
// Create the server
VertxServer rpcServer = VertxServerBuilder.forPort(vertx, 8080).addService(service).build();
// start the server
rpcServer.start(ar -> {
if (ar.failed()) {
ar.cause().printStackTrace();
}
});
}
use of io.vertx.grpc.VertxServer in project vertx-examples by vert-x3.
the class Server method start.
@Override
public void start() throws Exception {
VertxServer server = VertxServerBuilder.forAddress(vertx, "localhost", 8080).addService(new GreeterGrpc.GreeterVertxImplBase() {
@Override
public void sayHello(HelloRequest request, Promise<HelloReply> future) {
System.out.println("Hello " + request.getName());
future.complete(HelloReply.newBuilder().setMessage(request.getName()).build());
}
}).build();
server.start(ar -> {
if (ar.succeeded()) {
System.out.println("gRPC service started");
} else {
System.out.println("Could not start server " + ar.cause().getMessage());
}
});
}
use of io.vertx.grpc.VertxServer in project vertx-examples by vert-x3.
the class Server method start.
@Override
public void start() throws Exception {
VertxServer server = VertxServerBuilder.forPort(vertx, 8080).addService(new GreeterGrpc.GreeterVertxImplBase() {
@Override
public void sayHello(HelloRequest request, Promise<HelloReply> future) {
System.out.println("Hello " + request.getName());
future.complete(HelloReply.newBuilder().setMessage(request.getName()).build());
}
}).useSsl(options -> options.setSsl(true).setUseAlpn(true).setKeyStoreOptions(new JksOptions().setPath("tls/server-keystore.jks").setPassword("wibble"))).build();
server.start(ar -> {
if (ar.succeeded()) {
System.out.println("gRPC service started");
} else {
System.out.println("Could not start server " + ar.cause().getMessage());
}
});
}
Aggregations