Module: Google::Gax::Grpc
- Defined in:
- lib/google/gax/grpc.rb
Overview
Grpc adapts the gRPC surface
Constant Summary collapse
- STATUS_CODE_NAMES =
Hash[ GRPC::Core::StatusCodes.constants.map do |sym| [sym.to_s, GRPC::Core::StatusCodes.const_get(sym)] end ].freeze
- API_ERRORS =
[GRPC::BadStatus, GRPC::Cancelled].freeze
Class Method Summary collapse
-
.create_stub(service_path, port, channel: nil, chan_creds: nil, updater_proc: nil, scopes: nil, interceptors: []) {|address, creds, channel_override, interceptors| ... } ⇒ Object
Creates a gRPC client stub.
- .deserialize_error_status_details(error) ⇒ Object
Class Method Details
.create_stub(service_path, port, channel: nil, chan_creds: nil, updater_proc: nil, scopes: nil, interceptors: []) {|address, creds, channel_override, interceptors| ... } ⇒ Object
Creates a gRPC client stub.
116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 |
# File 'lib/google/gax/grpc.rb', line 116 def create_stub(service_path, port, channel: nil, chan_creds: nil, updater_proc: nil, scopes: nil, interceptors: []) verify_params(channel, chan_creds, updater_proc) address = "#{service_path}:#{port}" default_channel_args = { 'grpc.service_config_disable_resolution' => 1 } if channel yield(address, nil, channel_override: channel, interceptors: interceptors) elsif chan_creds yield(address, chan_creds, interceptors: interceptors, channel_args: default_channel_args) else if updater_proc.nil? auth_creds = Google::Auth.get_application_default(scopes) updater_proc = auth_creds.updater_proc end call_creds = GRPC::Core::CallCredentials.new(updater_proc) chan_creds = GRPC::Core::ChannelCredentials.new.compose(call_creds) yield(address, chan_creds, interceptors: interceptors, channel_args: default_channel_args) end end |
.deserialize_error_status_details(error) ⇒ Object
50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 |
# File 'lib/google/gax/grpc.rb', line 50 def deserialize_error_status_details(error) return unless error.is_a? GRPC::BadStatus # If error status is malformed, swallow the gRPC error that gets raised. begin details = GRPC::GoogleRpcStatusUtils.extract_google_rpc_status( error.to_status ).details rescue return 'Could not parse error details due to a malformed server '\ 'response trailer.' end return if details.nil? details = GRPC::GoogleRpcStatusUtils.extract_google_rpc_status( error.to_status ).details details.map do |any| # deserialize the proto wrapped by the Any in the error details begin type = Google::Protobuf::DescriptorPool.generated_pool.lookup( any.type_name ) any.unpack(type.msgclass) rescue any end end end |