Search in sources :

Example 6 with VertxServer

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());
        }
    });
}
Also used : JksOptions(io.vertx.core.net.JksOptions) VertxServer(io.vertx.grpc.VertxServer) HelloRequest(io.grpc.examples.helloworld.HelloRequest) Future(io.vertx.core.Future)

Example 7 with VertxServer

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();
        }
    });
}
Also used : Messages(io.vertx.example.grpc.Messages) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) VertxServer(io.vertx.grpc.VertxServer) GrpcWriteStream(io.vertx.grpc.GrpcWriteStream) ConsumerServiceGrpc(io.vertx.example.grpc.ConsumerServiceGrpc)

Example 8 with VertxServer

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();
        }
    });
}
Also used : GrpcBidiExchange(io.vertx.grpc.GrpcBidiExchange) ConversationalServiceGrpc(io.vertx.example.grpc.ConversationalServiceGrpc) Messages(io.vertx.example.grpc.Messages) VertxServer(io.vertx.grpc.VertxServer)

Example 9 with VertxServer

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());
        }
    });
}
Also used : Promise(io.vertx.core.Promise) VertxServer(io.vertx.grpc.VertxServer) HelloRequest(io.grpc.examples.helloworld.HelloRequest)

Example 10 with VertxServer

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());
        }
    });
}
Also used : AbstractVerticle(io.vertx.core.AbstractVerticle) Promise(io.vertx.core.Promise) JksOptions(io.vertx.core.net.JksOptions) GreeterGrpc(io.grpc.examples.helloworld.GreeterGrpc) HelloRequest(io.grpc.examples.helloworld.HelloRequest) Runner(io.vertx.example.grpc.util.Runner) VertxServerBuilder(io.vertx.grpc.VertxServerBuilder) HelloReply(io.grpc.examples.helloworld.HelloReply) VertxServer(io.vertx.grpc.VertxServer) JksOptions(io.vertx.core.net.JksOptions) VertxServer(io.vertx.grpc.VertxServer) HelloRequest(io.grpc.examples.helloworld.HelloRequest) GreeterGrpc(io.grpc.examples.helloworld.GreeterGrpc) HelloReply(io.grpc.examples.helloworld.HelloReply)

Aggregations

VertxServer (io.vertx.grpc.VertxServer)10 Promise (io.vertx.core.Promise)5 Messages (io.vertx.example.grpc.Messages)4 HelloRequest (io.grpc.examples.helloworld.HelloRequest)3 Future (io.vertx.core.Future)3 VertxServerBuilder (io.vertx.grpc.VertxServerBuilder)3 AbstractVerticle (io.vertx.core.AbstractVerticle)2 JksOptions (io.vertx.core.net.JksOptions)2 GrpcBidiExchange (io.vertx.grpc.GrpcBidiExchange)2 GrpcReadStream (io.vertx.grpc.GrpcReadStream)2 GrpcWriteStream (io.vertx.grpc.GrpcWriteStream)2 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)2 GreeterGrpc (io.grpc.examples.helloworld.GreeterGrpc)1 HelloReply (io.grpc.examples.helloworld.HelloReply)1 Feature (io.grpc.examples.routeguide.Feature)1 Point (io.grpc.examples.routeguide.Point)1 Rectangle (io.grpc.examples.routeguide.Rectangle)1 RouteNote (io.grpc.examples.routeguide.RouteNote)1 ConsumerServiceGrpc (io.vertx.example.grpc.ConsumerServiceGrpc)1 ConversationalServiceGrpc (io.vertx.example.grpc.ConversationalServiceGrpc)1