class Gapic::ServiceStub::ChannelPool


This class wraps multiple channels for sending RPCs.
Gapic gRPC ServiceStub ChannelPool
@private
#

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

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
  unless @config.channel_selection == :least_loaded
    warn "Invalid channel selection configuration, resorting to least loaded channel"
  end
  channel = least_loaded_channel
  channel.call_rpc method_name, request, options: options, &block
end

def create_channel

Creates a new channel.
#
def create_channel
  Channel.new @grpc_stub_class, endpoint: @endpoint, credentials: @credentials, channel_args: @channel_args,
              interceptors: @interceptors, on_channel_create: @config.on_channel_create,
              stub_logger: @stub_logger
end

def initialize grpc_stub_class,


Initialize an instance of ServiceStub::ChannelPool
#
def initialize grpc_stub_class,
               endpoint:, credentials:,
               channel_args: nil,
               interceptors: nil,
               config: nil,
               stub_logger: nil
  if credentials.is_a? ::GRPC::Core::Channel
    raise ArgumentError, "Can't create a channel pool with GRPC::Core::Channel as credentials"
  end
  @grpc_stub_class = grpc_stub_class
  @endpoint = endpoint
  @credentials = credentials
  @channel_args = channel_args
  @interceptors = interceptors
  @config = config || Configuration.new
  @stub_logger = stub_logger
  @channels = (1..@config.channel_count).map { create_channel }
end

def least_loaded_channel

Returns:
  • (::Grpc::ServiceStub::Channel) -
def least_loaded_channel
  @channels.min_by(&:concurrent_streams)
end