Class: Istox::GrpcClient

Inherits:
Object
  • Object
show all
Defined in:
lib/istox/helpers/grpc_client.rb

Class Method Summary collapse

Class Method Details

.add_host(host_type, url) ⇒ Object



6
7
8
9
10
# File 'lib/istox/helpers/grpc_client.rb', line 6

def add_host(host_type, url)
  @@hosts = {} unless defined?(@@hosts)

  @@hosts[host_type] = url
end

.add_interceptors(interceptor) ⇒ Object



12
13
14
15
16
# File 'lib/istox/helpers/grpc_client.rb', line 12

def add_interceptors(interceptor)
  @interceptors = [] unless defined?(@interceptors)

  @interceptors.push(interceptor)
end

.call(host_type, service, method, grpc_retries_count: 1, **keyword_args) ⇒ Object



22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/istox/helpers/grpc_client.rb', line 22

def call(host_type, service, method, grpc_retries_count: 1, **keyword_args)
  execute(host_type, service, method, **keyword_args)
rescue Gruf::Client::Errors::Unavailable => e
  # will retry three times with 1 seconds sleep between if there is a Unavailable error thrown from GRPC
  if grpc_retries_count < 3
    log.warn "GRPC failed to connect to #{host_type}, retrying after 1 seconds, retry count: #{grpc_retries_count}/3"
    sleep 1
    reinitiate_service(host_type, service)
    call(host_type, service, method, grpc_retries_count: grpc_retries_count + 1, **keyword_args)
  else
    log.fatal "GRPC unable connect to #{host_type}, throwing exception now."
    raise e
  end
end

.configure_grpc_loggerObject



18
19
20
# File 'lib/istox/helpers/grpc_client.rb', line 18

def configure_grpc_logger
 Gruf.grpc_logger = log
end

.default_channel_optionsObject



37
38
39
40
41
42
43
44
45
46
47
# File 'lib/istox/helpers/grpc_client.rb', line 37

def default_channel_options
  {
    'grpc.keepalive_time_ms' => 10_000, # send keepalive ping every 10 second, default is 2 hours
    'grpc.keepalive_timeout_ms' => 5000, # keepalive ping time out after 5 seconds, default is 20 seoncds
    'grpc.keepalive_permit_without_calls' => 1, # allow keepalive pings when there's no gRPC calls
    'grpc.http2.max_pings_without_data' => 0, # allow unlimited amount of keepalive pings without data
    'grpc.http2.min_time_between_pings_ms' => 10_000, # allow grpc pings from client every 10 seconds
    'grpc.http2.min_ping_interval_without_data_ms' => 5000, # allow grpc pings from client without data every 5 seconds
    'grpc.http2.max_ping_strikes' => 2 # How many misbehaving pings the server can bear before sending goaway and closing the transport
  }
end