Method: GRPC::ClientStub#initialize

Defined in:
src/ruby/lib/grpc/generic/client_stub.rb

#initialize(host, creds, channel_override: nil, timeout: nil, propagate_mask: nil, channel_args: {}, interceptors: []) ⇒ ClientStub

Creates a new ClientStub.

Minimally, a stub is created with the just the host of the gRPC service it wishes to access, e.g.,

my_stub = ClientStub.new(example.host.com:50505,
                         :this_channel_is_insecure)

If a channel_override argument is passed, it will be used as the underlying channel. Otherwise, the channel_args argument will be used to construct a new underlying channel.

There are some specific keyword args that are not used to configure the channel:

  • :channel_override

when present, this must be a pre-created GRPC::Core::Channel. If it’s present the host and arbitrary keyword arg areignored, and the RPC connection uses this channel.

  • :timeout

when present, this is the default timeout used for calls

Parameters:

  • host (String)

    the host the stub connects to

  • creds (Core::ChannelCredentials|Symbol)

    the channel credentials, or :this_channel_is_insecure, which explicitly indicates that the client should be created with an insecure connection. Note: this argument is ignored if the channel_override argument is provided.

  • channel_override (Core::Channel) (defaults to: nil)

    a pre-created channel

  • timeout (Number) (defaults to: nil)

    the default timeout to use in requests

  • propagate_mask (Number) (defaults to: nil)

    A bitwise combination of flags in GRPC::Core::PropagateMasks. Indicates how data should be propagated from parent server calls to child client calls if this client is being used within a gRPC server.

  • channel_args (Hash) (defaults to: {})

    the channel arguments. Note: this argument is ignored if the channel_override argument is provided.

  • interceptors (Array<GRPC::ClientInterceptor>) (defaults to: [])

    An array of GRPC::ClientInterceptor objects that will be used for intercepting calls before they are executed Interceptors are an EXPERIMENTAL API.



98
99
100
101
102
103
104
105
106
107
108
109
110
111
# File 'src/ruby/lib/grpc/generic/client_stub.rb', line 98

def initialize(host, creds,
               channel_override: nil,
               timeout: nil,
               propagate_mask: nil,
               channel_args: {},
               interceptors: [])
  @ch = ClientStub.setup_channel(channel_override, host, creds,
                                 channel_args.dup)
  alt_host = channel_args[Core::Channel::SSL_TARGET]
  @host = alt_host.nil? ? host : alt_host
  @propagate_mask = propagate_mask
  @timeout = timeout.nil? ? DEFAULT_TIMEOUT : timeout
  @interceptors = InterceptorRegistry.new(interceptors)
end