Search in sources :

Example 11 with HelloRequest

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

the class CustomHeaderClient method greet.

/**
 * A simple client method that like {@link io.grpc.examples.helloworld.HelloWorldClient}.
 */
private void greet(String name) {
    logger.info("Will try to greet " + name + " ...");
    HelloRequest request = HelloRequest.newBuilder().setName(name).build();
    HelloReply response;
    try {
        response = blockingStub.sayHello(request);
    } catch (StatusRuntimeException e) {
        logger.log(Level.WARNING, "RPC failed: {0}", e.getStatus());
        return;
    }
    logger.info("Greeting: " + response.getMessage());
}
Also used : HelloRequest(io.grpc.examples.helloworld.HelloRequest) StatusRuntimeException(io.grpc.StatusRuntimeException) HelloReply(io.grpc.examples.helloworld.HelloReply)

Example 12 with HelloRequest

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

the class HedgingHelloWorldClient method greet.

/**
 * Say hello to server.
 */
public void greet(String name) {
    HelloRequest request = HelloRequest.newBuilder().setName(name).build();
    HelloReply response = null;
    StatusRuntimeException statusRuntimeException = null;
    long startTime = System.nanoTime();
    try {
        response = blockingStub.sayHello(request);
    } catch (StatusRuntimeException e) {
        failedRpcs.incrementAndGet();
        statusRuntimeException = e;
    }
    long latencyMills = TimeUnit.NANOSECONDS.toMillis(System.nanoTime() - startTime);
    latencies.offer(latencyMills);
    if (statusRuntimeException == null) {
        logger.log(Level.INFO, "Greeting: {0}. Latency: {1}ms", new Object[] { response.getMessage(), latencyMills });
    } else {
        logger.log(Level.INFO, "RPC failed: {0}. Latency: {1}ms", new Object[] { statusRuntimeException.getStatus(), latencyMills });
    }
}
Also used : HelloRequest(io.grpc.examples.helloworld.HelloRequest) StatusRuntimeException(io.grpc.StatusRuntimeException) HelloReply(io.grpc.examples.helloworld.HelloReply)

Example 13 with HelloRequest

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

the class RetryingHelloWorldClient method greet.

/**
 * Say hello to server in a blocking unary call.
 */
public void greet(String name) {
    HelloRequest request = HelloRequest.newBuilder().setName(name).build();
    HelloReply response = null;
    StatusRuntimeException statusRuntimeException = null;
    try {
        response = blockingStub.sayHello(request);
    } catch (StatusRuntimeException e) {
        failedRpcs.incrementAndGet();
        statusRuntimeException = e;
    }
    totalRpcs.incrementAndGet();
    if (statusRuntimeException == null) {
        logger.log(Level.INFO, "Greeting: {0}", new Object[] { response.getMessage() });
    } else {
        logger.log(Level.INFO, "RPC failed: {0}", new Object[] { statusRuntimeException.getStatus() });
    }
}
Also used : HelloRequest(io.grpc.examples.helloworld.HelloRequest) StatusRuntimeException(io.grpc.StatusRuntimeException) HelloReply(io.grpc.examples.helloworld.HelloReply)

Example 14 with HelloRequest

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

the class SafeMethodCachingInterceptorTest method differentServiceCallsAreNotConflated.

@Test
public void differentServiceCallsAreNotConflated() {
    MethodDescriptor<HelloRequest, HelloReply> anotherSafeMethod = AnotherGreeterGrpc.getSayHelloMethod().toBuilder().setSafe(true).build();
    HelloReply reply1 = ClientCalls.blockingUnaryCall(channelToUse, safeGreeterSayHelloMethod, CallOptions.DEFAULT, message);
    HelloReply reply2 = ClientCalls.blockingUnaryCall(channelToUse, anotherSafeMethod, CallOptions.DEFAULT, message);
    assertNotEquals(reply1, reply2);
}
Also used : HelloRequest(io.grpc.examples.helloworld.HelloRequest) HelloReply(io.grpc.examples.helloworld.HelloReply) Test(org.junit.Test)

Example 15 with HelloRequest

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

the class SafeMethodCachingInterceptorTest method differentMethodCallsAreNotConflated.

@Test
public void differentMethodCallsAreNotConflated() {
    MethodDescriptor<HelloRequest, HelloReply> anotherSafeMethod = GreeterGrpc.getSayAnotherHelloMethod().toBuilder().setSafe(true).build();
    HelloReply reply1 = ClientCalls.blockingUnaryCall(channelToUse, safeGreeterSayHelloMethod, CallOptions.DEFAULT, message);
    HelloReply reply2 = ClientCalls.blockingUnaryCall(channelToUse, anotherSafeMethod, CallOptions.DEFAULT, message);
    assertNotEquals(reply1, reply2);
}
Also used : HelloRequest(io.grpc.examples.helloworld.HelloRequest) HelloReply(io.grpc.examples.helloworld.HelloReply) Test(org.junit.Test)

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