NAME

Google::gRPC::Client - Unary and streaming gRPC client interface over HTTP/2

SYNOPSIS

use Google::Auth;
use Google::gRPC::Client;
use Google::Cloud::Spanner::V1::Spanner; # or any Protobuf message classes

my $auth  = Google::Auth->default();
my $token = $auth->get_token();

my $client = Google::gRPC::Client->new(
    target      => 'spanner.googleapis.com:443',
    auth_token  => $token,
    timeout     => 30,    # seconds (or gRPC duration string such as '30S')
    max_retries => 3,
);

# Unary RPC call
my $response = $client->call({
    service        => 'google.spanner.v1.Spanner',
    method         => 'CreateSession',
    request        => $request_msg,
    response_class => 'Google::Cloud::Spanner::V1::Session',
});

# Streaming RPC call
my $stream = $client->stream(
    service        => 'google.spanner.v1.Spanner',
    method         => 'ExecuteStreamingSql',
    request        => $sql_request_msg,
    response_class => 'Google::Cloud::Spanner::V1::PartialResultSet',
    type           => 'server_streaming',
);
while (my $chunk = $stream->recv_message()) {
    ...
}

DESCRIPTION

Google::gRPC::Client implements the high-level gRPC client interface for Google Cloud Perl SDKs. It handles gRPC length-prefixed framing, HTTP/2 transport via Net::Curl::Easy (or Google::gRPC::Channel in offline mode), Bearer token and quota-project header injection, deadline propagation (grpc-timeout), exponential backoff retries on transient HTTP/gRPC errors, and optional connection pooling via Google::gRPC::ChannelPool.

CONSTRUCTOR / ATTRIBUTES

Pass these options to Google::gRPC::Client->new(...). Either target or channel_pool is required.

  • target

    The host:port endpoint to connect to (e.g., 'spanner.googleapis.com:443'). Optional if channel_pool is provided (defaults to the pool's target).

  • channel_pool

    An optional Google::gRPC::ChannelPool instance for load-balancing and pinning resolved IPs across multiple subchannels.

  • auth_token

    Optional OAuth 2.0 Bearer access token sent in the authorization header.

  • proxy

    Optional HTTP/HTTPS proxy URL passed to CURLOPT_PROXY.

  • engine_type

    Optional HTTP/2 engine selection passed to Google::gRPC::Channel (e.g., 'nghttp2' or 'pp').

  • timeout

    Optional default per-RPC deadline in seconds or gRPC timeout format (parsed via Google::gRPC::Deadline).

  • max_retries

    Maximum number of retry attempts on transient transport errors (HTTP 429, 502, 503, 504 or gRPC status UNAVAILABLE / 14). Defaults to 3.

  • initial_backoff_sec

    Initial retry backoff delay in seconds. Defaults to 0.1.

  • max_backoff_sec

    Maximum retry backoff delay in seconds. Defaults to 1.0.

  • backoff_factor

    Multiplier applied to the backoff delay after each retry. Defaults to 2.0.

  • offline

    Boolean flag enabling offline/in-memory channel execution via Google::gRPC::Channel without requiring Net::Curl::Easy. Defaults to true when $ENV{PERL_GRPC_OFFLINE} is set.

  • channel

    Lazy-built Google::gRPC::Channel (or the configured channel_pool).

METHODS

call

my $response = $client->call({
    service             => 'google.spanner.v1.Spanner',
    method              => 'CreateSession',
    request             => $request_obj_or_bytes,
    response_class      => 'Google::Cloud::Spanner::V1::Session',
    timeout             => 15,   # optional override
    max_retries         => 3,    # optional override
    initial_backoff_sec => 0.1,  # optional override
    max_backoff_sec     => 1.0,  # optional override
    backoff_factor      => 2.0,  # optional override
});

Executes a unary gRPC call. request may be a Protobuf message object implementing serialize() or raw serialized protobuf bytes. Returns an instance of response_class decoded via $response_class->parse($bytes). Croaks on transport errors, missing grpc-status trailers, or non-zero gRPC status codes after exhausting retries.

stream

my $stream = $client->stream(
    service        => 'google.spanner.v1.Spanner',
    method         => 'ExecuteStreamingSql',
    request        => $request_obj,
    response_class => 'Google::Cloud::Spanner::V1::PartialResultSet',
    type           => 'server_streaming',
);

Creates and returns a Google::gRPC::Stream via the underlying channel.

ENVIRONMENT VARIABLES

  • GOOGLE_CLOUD_QUOTA_PROJECT

    When set, sent as the x-goog-user-project gRPC metadata header on every call.

  • PERL_GRPC_OFFLINE

    When set to a true value, defaults offline to 1.

SEE ALSO

Google::gRPC, Google::gRPC::Channel, Google::gRPC::ChannelPool, Google::gRPC::Stream, Google::gRPC::Deadline, Google::gRPC::Status, Google::Auth

AUTHOR

C.J. Collier <cjac@google.com>

LICENSE

Apache License 2.0