Search in sources :

Example 1 with HelloRequest

use of io.grpc.examples.helloworld.HelloRequest in project vertx-examples by vert-x3.

the class Client method start.

@Override
public void start() throws Exception {
    ManagedChannel channel = VertxChannelBuilder.forAddress(vertx, "localhost", 8080).useSsl(options -> options.setSsl(true).setUseAlpn(true).setTrustStoreOptions(new JksOptions().setPath("tls/client-truststore.jks").setPassword("wibble"))).build();
    GreeterGrpc.GreeterVertxStub stub = GreeterGrpc.newVertxStub(channel);
    HelloRequest request = HelloRequest.newBuilder().setName("Julien").build();
    stub.sayHello(request, asyncResponse -> {
        if (asyncResponse.succeeded()) {
            System.out.println("Succeeded " + asyncResponse.result().getMessage());
        } else {
            asyncResponse.cause().printStackTrace();
        }
    });
}
Also used : ManagedChannel(io.grpc.ManagedChannel) 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) VertxChannelBuilder(io.vertx.grpc.VertxChannelBuilder) JksOptions(io.vertx.core.net.JksOptions) HelloRequest(io.grpc.examples.helloworld.HelloRequest) ManagedChannel(io.grpc.ManagedChannel) GreeterGrpc(io.grpc.examples.helloworld.GreeterGrpc)

Example 2 with HelloRequest

use of io.grpc.examples.helloworld.HelloRequest in project vertx-examples by vert-x3.

the class Client method start.

@Override
public void start() throws Exception {
    ManagedChannel channel = VertxChannelBuilder.forAddress(vertx, "localhost", 8080).usePlaintext(true).build();
    GreeterGrpc.GreeterVertxStub stub = GreeterGrpc.newVertxStub(channel);
    HelloRequest request = HelloRequest.newBuilder().setName("Julien").build();
    stub.sayHello(request, asyncResponse -> {
        if (asyncResponse.succeeded()) {
            System.out.println("Succeeded " + asyncResponse.result().getMessage());
        } else {
            asyncResponse.cause().printStackTrace();
        }
    });
}
Also used : HelloRequest(io.grpc.examples.helloworld.HelloRequest) ManagedChannel(io.grpc.ManagedChannel) GreeterGrpc(io.grpc.examples.helloworld.GreeterGrpc)

Example 3 with HelloRequest

use of io.grpc.examples.helloworld.HelloRequest in project vertx-openshift-it by cescoffier.

the class EdgeVerticle method grpc.

private void grpc(RoutingContext rc) {
    ManagedChannel channel = VertxChannelBuilder.forAddress(vertx, "hello", 8082).useSsl(options -> options.setSsl(true).setUseAlpn(true).setTrustAll(true)).build();
    GreeterGrpc.GreeterVertxStub stub = GreeterGrpc.newVertxStub(channel);
    HelloRequest request = HelloRequest.newBuilder().setName("OpenShift").build();
    System.out.println("Sending request...");
    stub.sayHello(request, asyncResponse -> {
        System.out.println("Got result");
        if (asyncResponse.succeeded()) {
            System.out.println("Succeeded " + asyncResponse.result().getMessage());
            rc.response().end(asyncResponse.result().getMessage());
        } else {
            rc.fail(asyncResponse.cause());
        }
    });
}
Also used : WebClientOptions(io.vertx.ext.web.client.WebClientOptions) ManagedChannel(io.grpc.ManagedChannel) HttpVersion(io.vertx.core.http.HttpVersion) WebClient(io.vertx.ext.web.client.WebClient) AbstractVerticle(io.vertx.core.AbstractVerticle) HttpServer(io.vertx.core.http.HttpServer) GreeterGrpc(io.grpc.examples.helloworld.GreeterGrpc) HelloRequest(io.grpc.examples.helloworld.HelloRequest) HttpServerOptions(io.vertx.core.http.HttpServerOptions) Router(io.vertx.ext.web.Router) RoutingContext(io.vertx.ext.web.RoutingContext) VertxChannelBuilder(io.vertx.grpc.VertxChannelBuilder) HelloRequest(io.grpc.examples.helloworld.HelloRequest) ManagedChannel(io.grpc.ManagedChannel) GreeterGrpc(io.grpc.examples.helloworld.GreeterGrpc)

Example 4 with HelloRequest

use of io.grpc.examples.helloworld.HelloRequest in project vertx-openshift-it by cescoffier.

the class Http2IT method testGRPC.

@Test
public void testGRPC() throws Exception {
    Assertions.assertThat(client).deployments().pods().isPodReadyForPeriod();
    String host = securedUrlForRoute(client.routes().withName("hello").get()).getHost();
    System.out.println("Host: " + host);
    System.out.println("Port: " + 443);
    ManagedChannel channel = VertxChannelBuilder.forAddress(vertx, host, 443).useSsl(options -> options.setSsl(true).setUseAlpn(true).setTrustAll(true)).build();
    GreeterGrpc.GreeterVertxStub stub = GreeterGrpc.newVertxStub(channel);
    HelloRequest request = HelloRequest.newBuilder().setName("OpenShift").build();
    AtomicReference<String> result = new AtomicReference<>();
    System.out.println("Sending request...");
    stub.sayHello(request, asyncResponse -> {
        System.out.println("Got result");
        if (asyncResponse.succeeded()) {
            System.out.println("Succeeded " + asyncResponse.result().getMessage());
            result.set(asyncResponse.result().getMessage());
        } else {
            asyncResponse.cause().printStackTrace();
        }
    });
    await().atMost(5, TimeUnit.MINUTES).untilAtomic(result, is(notNullValue()));
    assertThat(result.get()).contains("Hello OpenShift");
}
Also used : Awaitility.await(org.awaitility.Awaitility.await) ManagedChannel(io.grpc.ManagedChannel) Matchers.notNullValue(org.hamcrest.Matchers.notNullValue) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) Vertx(io.vertx.core.Vertx) GreeterGrpc(io.grpc.examples.helloworld.GreeterGrpc) HelloRequest(io.grpc.examples.helloworld.HelloRequest) IOException(java.io.IOException) AtomicReference(java.util.concurrent.atomic.AtomicReference) VertxChannelBuilder(io.vertx.grpc.VertxChannelBuilder) Assertions(io.fabric8.kubernetes.assertions.Assertions) TimeUnit(java.util.concurrent.TimeUnit) Kube.securedUrlForRoute(io.vertx.it.openshift.utils.Kube.securedUrlForRoute) HttpVersion(io.vertx.core.http.HttpVersion) AbstractTestClass(io.vertx.it.openshift.utils.AbstractTestClass) Matchers.is(org.hamcrest.Matchers.is) HttpClientOptions(io.vertx.core.http.HttpClientOptions) org.junit(org.junit) Kube.urlForRoute(io.vertx.it.openshift.utils.Kube.urlForRoute) HelloRequest(io.grpc.examples.helloworld.HelloRequest) ManagedChannel(io.grpc.ManagedChannel) GreeterGrpc(io.grpc.examples.helloworld.GreeterGrpc) AtomicReference(java.util.concurrent.atomic.AtomicReference)

Example 5 with HelloRequest

use of io.grpc.examples.helloworld.HelloRequest in project pinpoint by naver.

the class HelloWorldSimpleClient method greet.

public String greet(String name) {
    HelloRequest request = HelloRequest.newBuilder().setName(name).build();
    HelloReply response = blockingStub.sayHello(request);
    logger.info("Greeting: {}" + response.getMessage());
    return response.getMessage();
}
Also used : HelloRequest(io.grpc.examples.helloworld.HelloRequest) HelloReply(io.grpc.examples.helloworld.HelloReply)

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