class Gapic::ServiceStub


@return [Gapic::ServiceStub::ChannelPool] The instance of the ChannelPool class.
@!attribute [r] channel_pool
@return [Object] The instance of the gRPC stub class (‘grpc_stub_class`) constructor argument.
@!attribute [r] grpc_stub
This class wraps the actual gRPC Stub and ChannelPool objects.
Gapic gRPC Stub
#

def call_rpc method_name, request, options: nil, &block

Other tags:
    Example: Accessing the response and RPC operation using a block: -
    Example: Using custom call options: -

Returns:
  • (Object) - The response object.

Other tags:
    Yieldparam: operation - The RPC operation for the response.
    Yieldparam: response - The response object.

Other tags:
    Yield: - Access the response along with the RPC operation.

Parameters:
  • options (Gapic::CallOptions, Hash) -- The options for making the RPC call. A Hash can be provided to
  • request (Object) -- The request object.
  • method_name (Symbol) -- The RPC method name.
def call_rpc method_name, request, options: nil, &block
  if @channel_pool.nil?
    meth = @grpc_stub.method method_name
    rpc_call = RpcCall.new meth, stub_logger: stub_logger, method_name: method_name
    rpc_call.call request, options: options, &block
  else
    @channel_pool.call_rpc method_name, request, options: options, &block
  end
end

def create_channel_pool grpc_stub_class, endpoint:, credentials:, channel_args: nil,

def create_channel_pool grpc_stub_class, endpoint:, credentials:, channel_args: nil,
                        interceptors: nil, channel_pool_config: nil
  if credentials.is_a? ::GRPC::Core::Channel
    raise ArgumentError, "Cannot create a channel pool with GRPC::Core::Channel as credentials"
  end
  @channel_pool = ChannelPool.new grpc_stub_class, endpoint: endpoint, credentials: credentials,
                    channel_args: channel_args, interceptors: interceptors,
                    config: channel_pool_config, stub_logger: stub_logger
end

def create_grpc_stub grpc_stub_class, endpoint:, credentials:, channel_args: nil, interceptors: nil

def create_grpc_stub grpc_stub_class, endpoint:, credentials:, channel_args: nil, interceptors: nil
  @grpc_stub = case credentials
               when ::GRPC::Core::Channel
                 grpc_stub_class.new endpoint, nil, channel_override: credentials,
                                     interceptors: interceptors
               when ::GRPC::Core::ChannelCredentials, Symbol
                 grpc_stub_class.new endpoint, credentials, channel_args: channel_args,
                                     interceptors: interceptors
               else
                 updater_proc = credentials.updater_proc if credentials.respond_to? :updater_proc
                 updater_proc ||= credentials if credentials.is_a? Proc
                 raise ArgumentError, "invalid credentials (#{credentials.class})" if updater_proc.nil?
                 call_creds = ::GRPC::Core::CallCredentials.new updater_proc
                 chan_creds = ::GRPC::Core::ChannelCredentials.new.compose call_creds
                 grpc_stub_class.new endpoint, chan_creds, channel_args: channel_args,
                                     interceptors: interceptors
               end
end

def initialize grpc_stub_class,

Parameters:
  • logger (Logger, :default, nil) -- An explicit logger to use, or one
  • channel_pool_config (::Gapic::ServiceStub:ChannelPool::Configuration) -- The configuration for channel
  • interceptors (Array<::GRPC::ClientInterceptor>) -- An array of {::GRPC::ClientInterceptor} objects that will
  • channel_args (Hash) -- The channel arguments. (This argument is ignored when `credentials` is
  • credentials (Google::Auth::Credentials, Signet::OAuth2::Client, String, Hash, Proc, ) -- redentials [Google::Auth::Credentials, Signet::OAuth2::Client, String, Hash, Proc,
  • universe_domain (String) -- The universe domain in which calls should
  • endpoint_template (String) -- The endpoint of the API, where the
  • endpoint (String) -- The endpoint of the API. Overrides any endpoint_template.
  • grpc_stub_class (Class) -- gRPC stub class to create a new instance of.
def initialize grpc_stub_class,
               credentials:,
               endpoint: nil,
               endpoint_template: nil,
               universe_domain: nil,
               channel_args: nil,
               interceptors: nil,
               channel_pool_config: nil,
               logger: :default
  raise ArgumentError, "grpc_stub_class is required" if grpc_stub_class.nil?
  setup_universe_domain universe_domain: universe_domain,
                        endpoint: endpoint,
                        endpoint_template: endpoint_template,
                        credentials: credentials
  setup_logging logger: logger,
                system_name: grpc_stub_class,
                service: grpc_stub_class,
                endpoint: self.endpoint,
                client_id: object_id
  @channel_pool = nil
  @grpc_stub = nil
  channel_args = Hash channel_args
  interceptors = Array interceptors
  if channel_pool_config && channel_pool_config.channel_count > 1
    create_channel_pool grpc_stub_class, endpoint: self.endpoint, credentials: self.credentials,
                        channel_args: channel_args, interceptors: interceptors,
                        channel_pool_config: channel_pool_config
  else
    create_grpc_stub grpc_stub_class, endpoint: self.endpoint, credentials: self.credentials,
                     channel_args: channel_args, interceptors: interceptors
  end
end