Class: Istox::GrpcClient
- Inherits:
-
Object
- Object
- Istox::GrpcClient
- Defined in:
- lib/istox/helpers/grpc_client.rb
Class Method Summary collapse
- .add_host(host_type, url, cert: nil) ⇒ Object
- .add_interceptors(interceptor) ⇒ Object
- .call(host_type, service, method, grpc_retries_count: 1, **keyword_args) ⇒ Object
- .configure_grpc_logger ⇒ Object
- .default_channel_options ⇒ Object
Class Method Details
.add_host(host_type, url, cert: nil) ⇒ Object
6 7 8 9 10 11 12 |
# File 'lib/istox/helpers/grpc_client.rb', line 6 def add_host(host_type, url, cert: nil) @@hosts = {} unless defined?(@@hosts) @@certs = {} unless defined?(@@certs) @@hosts[host_type] = url @@certs[host_type] = cert end |
.add_interceptors(interceptor) ⇒ Object
14 15 16 17 18 |
# File 'lib/istox/helpers/grpc_client.rb', line 14 def add_interceptors(interceptor) @interceptors = [] unless defined?(@interceptors) @interceptors.push(interceptor) end |
.call(host_type, service, method, grpc_retries_count: 1, **keyword_args) ⇒ Object
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/istox/helpers/grpc_client.rb', line 24 def call(host_type, service, method, grpc_retries_count: 1, **keyword_args) execute(host_type, service, method, **keyword_args) rescue Gruf::Client::Errors => e if e.is_a? Gruf::Client::Errors::Unavailable # 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 else log.info e raise e end end |
.configure_grpc_logger ⇒ Object
20 21 22 |
# File 'lib/istox/helpers/grpc_client.rb', line 20 def configure_grpc_logger Gruf.grpc_logger = log end |
.default_channel_options ⇒ Object
44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/istox/helpers/grpc_client.rb', line 44 def { '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 |