Search in sources :

Example 1 with GrpcServiceClient

use of io.helidon.grpc.client.GrpcServiceClient in project helidon by oracle.

the class SecureStringClient method main.

/**
 * Program entry point.
 *
 * @param args  the program arguments - {@code arg[0]} is the user name
 *              and {@code arg[1] is the password}
 */
public static void main(String[] args) {
    Channel channel = ManagedChannelBuilder.forAddress("localhost", 1408).usePlaintext().build();
    // Obtain the user name and password from the program arguments
    String user = args.length >= 2 ? args[0] : "Ted";
    String password = args.length >= 2 ? args[1] : "secret";
    Config config = Config.create();
    // configure Helidon security and add the basic auth provider
    Security security = Security.builder().addProvider(HttpBasicAuthProvider.create(config.get("http-basic-auth"))).build();
    // create the gRPC client security call credentials
    // setting the properties used by the basic auth provider for user name and password
    GrpcClientSecurity clientSecurity = GrpcClientSecurity.builder(security.createContext("test.client")).property(HttpBasicAuthProvider.EP_PROPERTY_OUTBOUND_USER, user).property(HttpBasicAuthProvider.EP_PROPERTY_OUTBOUND_PASSWORD, password).build();
    // Create the client service descriptor and add the call credentials
    ClientServiceDescriptor descriptor = ClientServiceDescriptor.builder(StringServiceGrpc.getServiceDescriptor()).callCredentials(clientSecurity).build();
    // create the client for the service
    GrpcServiceClient client = GrpcServiceClient.create(channel, descriptor);
    Strings.StringMessage request = Strings.StringMessage.newBuilder().setText("ABCDE").build();
    Strings.StringMessage response = client.blockingUnary("Lower", request);
    System.out.println("Response from Lower method call is '" + response.getText() + "'");
}
Also used : GrpcClientSecurity(io.helidon.security.integration.grpc.GrpcClientSecurity) Config(io.helidon.config.Config) Channel(io.grpc.Channel) ClientServiceDescriptor(io.helidon.grpc.client.ClientServiceDescriptor) GrpcServiceClient(io.helidon.grpc.client.GrpcServiceClient) Security(io.helidon.security.Security) GrpcClientSecurity(io.helidon.security.integration.grpc.GrpcClientSecurity) Strings(io.helidon.grpc.examples.common.Strings)

Example 2 with GrpcServiceClient

use of io.helidon.grpc.client.GrpcServiceClient in project helidon by oracle.

the class SecureGreetClient method main.

/**
 * Main entry point.
 *
 * @param args  the program arguments - {@code arg[0]} is the user name
 *              and {@code arg[1] is the password}
 */
public static void main(String[] args) {
    Channel channel = ManagedChannelBuilder.forAddress("localhost", 1408).usePlaintext().build();
    // Obtain the user name and password from the program arguments
    String user = args.length >= 2 ? args[0] : "Ted";
    String password = args.length >= 2 ? args[1] : "secret";
    Config config = Config.create();
    // configure Helidon security and add the basic auth provider
    Security security = Security.builder().addProvider(HttpBasicAuthProvider.create(config.get("http-basic-auth"))).build();
    // create the gRPC client security call credentials
    // setting the properties used by the basic auth provider for user name and password
    GrpcClientSecurity clientSecurity = GrpcClientSecurity.builder(security.createContext("test.client")).property(HttpBasicAuthProvider.EP_PROPERTY_OUTBOUND_USER, user).property(HttpBasicAuthProvider.EP_PROPERTY_OUTBOUND_PASSWORD, password).build();
    // Create the client service descriptor and add the call credentials
    ClientServiceDescriptor descriptor = ClientServiceDescriptor.builder(GreetServiceGrpc.getServiceDescriptor()).callCredentials(clientSecurity).build();
    // create the client for the service
    GrpcServiceClient client = GrpcServiceClient.create(channel, descriptor);
    greet(client);
    setGreeting(client);
    greet(client);
}
Also used : GrpcClientSecurity(io.helidon.security.integration.grpc.GrpcClientSecurity) Config(io.helidon.config.Config) Channel(io.grpc.Channel) ClientServiceDescriptor(io.helidon.grpc.client.ClientServiceDescriptor) GrpcServiceClient(io.helidon.grpc.client.GrpcServiceClient) Security(io.helidon.security.Security) GrpcClientSecurity(io.helidon.security.integration.grpc.GrpcClientSecurity)

Example 3 with GrpcServiceClient

use of io.helidon.grpc.client.GrpcServiceClient in project helidon by oracle.

the class StringClient method main.

/**
 * Program entry point.
 *
 * @param args  the program arguments
 *
 * @throws Exception if an error occurs
 */
public static void main(String[] args) throws Exception {
    ClientServiceDescriptor descriptor = ClientServiceDescriptor.builder(StringServiceGrpc.getServiceDescriptor()).build();
    Channel channel = ManagedChannelBuilder.forAddress("localhost", 1408).usePlaintext().build();
    GrpcServiceClient client = GrpcServiceClient.create(channel, descriptor);
    unary(client);
    asyncUnary(client);
    blockingUnary(client);
    clientStreaming(client);
    clientStreamingOfIterable(client);
    serverStreamingBlocking(client);
    serverStreaming(client);
    bidirectional(client);
}
Also used : ClientServiceDescriptor(io.helidon.grpc.client.ClientServiceDescriptor) Channel(io.grpc.Channel) GrpcServiceClient(io.helidon.grpc.client.GrpcServiceClient)

Example 4 with GrpcServiceClient

use of io.helidon.grpc.client.GrpcServiceClient in project helidon by oracle.

the class HealthClient method main.

/**
 * The program entry point.
 *
 * @param args  the program arguments
 */
public static void main(String[] args) {
    ClientServiceDescriptor descriptor = ClientServiceDescriptor.builder(HealthGrpc.getServiceDescriptor()).build();
    Channel channel = ManagedChannelBuilder.forAddress("localhost", 1408).usePlaintext().build();
    GrpcServiceClient grpcClient = GrpcServiceClient.create(channel, descriptor);
    // query the health of a deployed service
    HealthCheckResponse response = grpcClient.blockingUnary("Check", HealthCheckRequest.newBuilder().setService("GreetService").build());
    System.out.println(response);
    // query the health of a non-existent service
    try {
        grpcClient.blockingUnary("Check", HealthCheckRequest.newBuilder().setService("FooService").build());
    } catch (StatusRuntimeException e) {
        // expect to catch a NOT_FOUND exception
        System.out.println(e.getMessage());
    }
}
Also used : HealthCheckResponse(io.grpc.health.v1.HealthCheckResponse) ClientServiceDescriptor(io.helidon.grpc.client.ClientServiceDescriptor) Channel(io.grpc.Channel) StatusRuntimeException(io.grpc.StatusRuntimeException) GrpcServiceClient(io.helidon.grpc.client.GrpcServiceClient)

Example 5 with GrpcServiceClient

use of io.helidon.grpc.client.GrpcServiceClient 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)5 ClientServiceDescriptor (io.helidon.grpc.client.ClientServiceDescriptor)5 GrpcServiceClient (io.helidon.grpc.client.GrpcServiceClient)5 Config (io.helidon.config.Config)2 Security (io.helidon.security.Security)2 GrpcClientSecurity (io.helidon.security.integration.grpc.GrpcClientSecurity)2 StatusRuntimeException (io.grpc.StatusRuntimeException)1 HealthCheckResponse (io.grpc.health.v1.HealthCheckResponse)1 ClientTracingInterceptor (io.helidon.grpc.client.ClientTracingInterceptor)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 Strings (io.helidon.grpc.examples.common.Strings)1 Tracer (io.opentracing.Tracer)1