Search in sources :

Example 1 with SetGreetingResponse

use of io.helidon.grpc.examples.common.Greet.SetGreetingResponse in project helidon by oracle.

the class GreetClient method main.

/**
 * The program entry point.
 *
 * @param args  the program arguments
 */
public static void main(String[] args) {
    Tracer tracer = TracerBuilder.create("Client").collectorUri(URI.create("http://localhost:9411/api/v2/spans")).build();
    ClientTracingInterceptor tracingInterceptor = ClientTracingInterceptor.builder(tracer).withVerbosity().withTracedAttributes(ClientRequestAttribute.ALL_CALL_OPTIONS).build();
    ClientServiceDescriptor descriptor = ClientServiceDescriptor.builder(GreetServiceGrpc.getServiceDescriptor()).intercept(tracingInterceptor).build();
    Channel channel = ManagedChannelBuilder.forAddress("localhost", 1408).usePlaintext().build();
    GrpcServiceClient client = GrpcServiceClient.create(channel, descriptor);
    // Obtain a greeting from the GreetService
    GreetRequest request = GreetRequest.newBuilder().setName("Aleks").build();
    GreetResponse firstGreeting = client.blockingUnary("Greet", request);
    System.out.println("First greeting: '" + firstGreeting.getMessage() + "'");
    // Change the greeting
    SetGreetingRequest setRequest = SetGreetingRequest.newBuilder().setGreeting("Ciao").build();
    SetGreetingResponse setResponse = client.blockingUnary("SetGreeting", setRequest);
    System.out.println("Greeting set to: '" + setResponse.getGreeting() + "'");
    // Obtain a second greeting from the GreetService
    GreetResponse secondGreeting = client.blockingUnary("Greet", request);
    System.out.println("Second greeting: '" + secondGreeting.getMessage() + "'");
}
Also used : ClientTracingInterceptor(io.helidon.grpc.client.ClientTracingInterceptor) GreetResponse(io.helidon.grpc.examples.common.Greet.GreetResponse) GreetRequest(io.helidon.grpc.examples.common.Greet.GreetRequest) Tracer(io.opentracing.Tracer) ClientServiceDescriptor(io.helidon.grpc.client.ClientServiceDescriptor) Channel(io.grpc.Channel) GrpcServiceClient(io.helidon.grpc.client.GrpcServiceClient) SetGreetingResponse(io.helidon.grpc.examples.common.Greet.SetGreetingResponse) SetGreetingRequest(io.helidon.grpc.examples.common.Greet.SetGreetingRequest)

Aggregations

Channel (io.grpc.Channel)1 ClientServiceDescriptor (io.helidon.grpc.client.ClientServiceDescriptor)1 ClientTracingInterceptor (io.helidon.grpc.client.ClientTracingInterceptor)1 GrpcServiceClient (io.helidon.grpc.client.GrpcServiceClient)1 GreetRequest (io.helidon.grpc.examples.common.Greet.GreetRequest)1 GreetResponse (io.helidon.grpc.examples.common.Greet.GreetResponse)1 SetGreetingRequest (io.helidon.grpc.examples.common.Greet.SetGreetingRequest)1 SetGreetingResponse (io.helidon.grpc.examples.common.Greet.SetGreetingResponse)1 Tracer (io.opentracing.Tracer)1