Search in sources :

Example 16 with HelloRequest

use of io.grpc.examples.helloworld.HelloRequest 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, Future<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) 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) Future(io.vertx.core.Future) 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)

Example 17 with HelloRequest

use of io.grpc.examples.helloworld.HelloRequest 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, Future<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 : VertxServer(io.vertx.grpc.VertxServer) HelloRequest(io.grpc.examples.helloworld.HelloRequest) Future(io.vertx.core.Future)

Example 18 with HelloRequest

use of io.grpc.examples.helloworld.HelloRequest 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 19 with HelloRequest

use of io.grpc.examples.helloworld.HelloRequest in project grpc-java by grpc.

the class HeaderClientInterceptorTest method clientHeaderDeliveredToServer.

@Test
public void clientHeaderDeliveredToServer() throws Exception {
    // Generate a unique in-process server name.
    String serverName = InProcessServerBuilder.generateName();
    // Create a server, add service, start, and register for automatic graceful shutdown.
    grpcCleanup.register(InProcessServerBuilder.forName(serverName).directExecutor().addService(ServerInterceptors.intercept(new GreeterImplBase() {
    }, mockServerInterceptor)).build().start());
    // Create a client channel and register for automatic graceful shutdown.
    ManagedChannel channel = grpcCleanup.register(InProcessChannelBuilder.forName(serverName).directExecutor().build());
    GreeterBlockingStub blockingStub = GreeterGrpc.newBlockingStub(ClientInterceptors.intercept(channel, new HeaderClientInterceptor()));
    ArgumentCaptor<Metadata> metadataCaptor = ArgumentCaptor.forClass(Metadata.class);
    try {
        blockingStub.sayHello(HelloRequest.getDefaultInstance());
        fail();
    } catch (StatusRuntimeException expected) {
    // expected because the method is not implemented at server side
    }
    verify(mockServerInterceptor).interceptCall(ArgumentMatchers.<ServerCall<HelloRequest, HelloReply>>any(), metadataCaptor.capture(), ArgumentMatchers.<ServerCallHandler<HelloRequest, HelloReply>>any());
    assertEquals("customRequestValue", metadataCaptor.getValue().get(HeaderClientInterceptor.CUSTOM_HEADER_KEY));
}
Also used : GreeterImplBase(io.grpc.examples.helloworld.GreeterGrpc.GreeterImplBase) GreeterBlockingStub(io.grpc.examples.helloworld.GreeterGrpc.GreeterBlockingStub) Metadata(io.grpc.Metadata) StatusRuntimeException(io.grpc.StatusRuntimeException) HelloRequest(io.grpc.examples.helloworld.HelloRequest) ManagedChannel(io.grpc.ManagedChannel) HelloReply(io.grpc.examples.helloworld.HelloReply) Test(org.junit.Test)

Example 20 with HelloRequest

use of io.grpc.examples.helloworld.HelloRequest in project grpc-java by grpc.

the class HeaderServerInterceptorTest method setUp.

@Before
public void setUp() throws Exception {
    GreeterImplBase greeterImplBase = new GreeterImplBase() {

        @Override
        public void sayHello(HelloRequest request, StreamObserver<HelloReply> responseObserver) {
            responseObserver.onNext(HelloReply.getDefaultInstance());
            responseObserver.onCompleted();
        }
    };
    // Generate a unique in-process server name.
    String serverName = InProcessServerBuilder.generateName();
    // Create a server, add service, start, and register for automatic graceful shutdown.
    grpcCleanup.register(InProcessServerBuilder.forName(serverName).directExecutor().addService(ServerInterceptors.intercept(greeterImplBase, new HeaderServerInterceptor())).build().start());
    // Create a client channel and register for automatic graceful shutdown.
    channel = grpcCleanup.register(InProcessChannelBuilder.forName(serverName).directExecutor().build());
}
Also used : GreeterImplBase(io.grpc.examples.helloworld.GreeterGrpc.GreeterImplBase) StreamObserver(io.grpc.stub.StreamObserver) HelloRequest(io.grpc.examples.helloworld.HelloRequest) Before(org.junit.Before)

Aggregations

HelloRequest (io.grpc.examples.helloworld.HelloRequest)27 HelloReply (io.grpc.examples.helloworld.HelloReply)20 StatusRuntimeException (io.grpc.StatusRuntimeException)8 GreeterGrpc (io.grpc.examples.helloworld.GreeterGrpc)8 ManagedChannel (io.grpc.ManagedChannel)6 Metadata (io.grpc.Metadata)4 CountDownLatch (java.util.concurrent.CountDownLatch)4 Status (io.grpc.Status)3 StreamObserver (io.grpc.stub.StreamObserver)3 AbstractVerticle (io.vertx.core.AbstractVerticle)3 Future (io.vertx.core.Future)3 JksOptions (io.vertx.core.net.JksOptions)3 VertxChannelBuilder (io.vertx.grpc.VertxChannelBuilder)3 VertxServer (io.vertx.grpc.VertxServer)3 Test (org.junit.Test)3 ClientCall (io.grpc.ClientCall)2 Server (io.grpc.Server)2 GreeterImplBase (io.grpc.examples.helloworld.GreeterGrpc.GreeterImplBase)2 GreeterStub (io.grpc.examples.helloworld.GreeterGrpc.GreeterStub)2 HttpVersion (io.vertx.core.http.HttpVersion)2