Module: StatelyDB::Common::Net

Defined in:
lib/common/net/conn.rb

Overview

A module for Stately Cloud networking code

Class Method Summary collapse

Class Method Details

.new_channel(endpoint:) ⇒ GRPC::Core::Channel

Create a new gRPC channel

Parameters:

  • endpoint (String)

    The endpoint to connect to

Returns:

  • (GRPC::Core::Channel)

    The new channel



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/common/net/conn.rb', line 13

def self.new_channel(endpoint:)
  endpoint_uri = URI(endpoint)
  creds = GRPC::Core::ChannelCredentials.new
  call_creds = GRPC::Core::CallCredentials.new(proc {})
  creds = if endpoint_uri.scheme == "http"
            :this_channel_is_insecure
          else
            creds.compose(call_creds)
          end
  GRPC::Core::Channel.new(endpoint_uri.authority, {
                            # This map contains grpc channel settings.
                            # Find the full list of supported keys
                            # here: https://grpc.github.io/grpc/core/group__grpc__arg__keys.html

                            # 2x the default of 8kb = 16kb
                            # Set max and absolute max to the same value
                            # to stop the grpc lib changing the error code to ResourceExhausted
                            # while still successfully reading the metadata because only the soft
                            # limit was exceeded.
                            "grpc.max_metadata_size" => 8192 * 2,
                            "grpc.absolute_max_metadata_size" => 8192 * 2
                          }, creds)
end