Module: Google::Gax::Grpc

Defined in:
lib/google/gax/grpc.rb

Overview

Grpc adapts the gRPC surface

Constant Summary collapse

STATUS_CODE_NAMES =
Hash[
  GRPC::Core::StatusCodes.constants.map do |sym|
    [sym.to_s, GRPC::Core::StatusCodes.const_get(sym)]
  end
].freeze
API_ERRORS =
[GRPC::BadStatus, GRPC::Cancelled].freeze

Class Method Summary collapse

Class Method Details

.create_stub(service_path, port, chan_creds: nil, channel: nil, updater_proc: nil, scopes: nil) {|address, creds| ... } ⇒ Object

Creates a gRPC client stub.

Parameters:

  • service_path (String)

    The domain name of the API remote host.

  • port (Fixnum)

    The port on which to connect to the remote host.

  • chan_creds (Grpc::Core::ChannelCredentials) (defaults to: nil)

    A ChannelCredentials object for use with an SSL-enabled Channel. If nil, credentials are pulled from a default location.

  • channel (Object) (defaults to: nil)

    A Channel object through which to make calls. If nil, a secure channel is constructed.

  • updater_proc (Proc) (defaults to: nil)

    A function that transforms the metadata for requests, e.g., to give OAuth credentials.

  • scopes (Array<String>) (defaults to: nil)

    The OAuth scopes for this service. This parameter is ignored if a custom metadata_transformer is supplied.

Yields:

  • (address, creds)

    the generated gRPC method to create a stub.

Returns:

  • A gRPC client stub.



73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
# File 'lib/google/gax/grpc.rb', line 73

def create_stub(service_path,
                port,
                chan_creds: nil,
                channel: nil,
                updater_proc: nil,
                scopes: nil)
  address = "#{service_path}:#{port}"
  if channel.nil?
    chan_creds = GRPC::Core::ChannelCredentials.new if chan_creds.nil?
    if updater_proc.nil?
      auth_creds = Google::Auth.get_application_default(scopes)
      updater_proc = auth_creds.updater_proc
    end
    call_creds = GRPC::Core::CallCredentials.new(updater_proc)
    chan_creds = chan_creds.compose(call_creds)
    yield(address, chan_creds)
  else
    yield(address, nil, channel_override: channel)
  end
end