最近,我尝试使用 rubygem grpc 版本 1.3.2 作为 clinet 并连接到由 golang 构建的 grpc 服务器。我浏览了GRPC.IO上的文档,并在我的代码中使用了它。
irb(main):017:0> GRPC::Core::Credentials.new(File.read(CA_FILE_PATH))
NameError: uninitialized constant GRPC::Core::Credentials
from (irb):17
from /usr/local/share/gems/gems/railties-4.2.1/lib/rails/commands/console.rb:110:in `start'
from /usr/local/share/gems/gems/railties-4.2.1/lib/rails/commands/console.rb:9:in `start'
from /usr/local/share/gems/gems/railties-4.2.1/lib/rails/commands/commands_tasks.rb:68:in `console'
from /usr/local/share/gems/gems/railties-4.2.1/lib/rails/commands/commands_tasks.rb:39:in `run_command!'
from /usr/local/share/gems/gems/railties-4.2.1/lib/rails/commands.rb:17:in `<top (required)>'
from bin/rails:4:in `require'
from bin/rails:4:in `<main>'
Run Code Online (Sandbox Code Playgroud)
然而他们的文件明确指出,
creds = GRPC::Core::Credentials.new(load_certs) # load_certs typically loads a CA roots file
stub = Helloworld::Greeter::Stub.new('myservice.example.com', creds)
Run Code Online (Sandbox Code Playgroud)
然后我遇到了ChannelCredentials,信用应该是ChannelCredentials对象或符号(例如:this_channel_is_insecure)。因此,我也尝试了一下。
我从 grpc gem 的源代码本身中获取了以下函数。在 rspec 测试用例中调用此函数来加载证书:
def load_certs
data_dir = "#{Rails.root}/certs" …Run Code Online (Sandbox Code Playgroud)