Ruby 版服务器框架
前提条件
服务器实现所需的 Gem:
- google-protobuf(本教程中使用的是 3.2.X)
- grpc(本教程中使用的是 1.2.X)
下载服务定义,然后创建以下目录结构:
[base_dir]
├── certificates
├── lib
├── protos
└── booking_service.proto
└── server.rb
根据接口说明生成 Ruby 库:
$ cd [base_dir]
$ grpc_tools_ruby_protoc -I protos --ruby_out=lib --grpc_out=lib protos/booking_service.proto
实现服务器
如果您需要框架代码,请咨询 Google 联系人。
在不使用 TLS 的情况下测试服务器
对于初始测试,可以停用 TLS:
$ cd [base_dir]
$ ruby server.rb --disable_tls
这不适合用于生产环境!
如需在服务器上启用 TLS,需要以下文件:
certificates/server.pem
服务器的证书链(采用 PEM 格式)
certificates/server.key
服务器证书链的私钥
certificates/trusted_client_roots.pem
在对客户端进行身份验证时信任的根证书
在对客户端进行身份验证时,会使用一组可信客户端根证书。您可以选择从 Mozilla 等权威机构获取这组受信任的根证书,也可以安装 Google Internet Authority G2 目前推荐的一组根证书。在后一种情况下,您有时可能需要手动更新根证书。
最终目录结构
[base_dir]
├── certificates
├── server.pem
├── server.key
└── trusted_client_roots.pem
├── lib
├── booking_service_pb.rb
└── booking_service_services_pb.rb
├── protos
└── booking_service.proto
└── server.rb
如未另行说明,那么本页面中的内容已根据知识共享署名 4.0 许可获得了许可,并且代码示例已根据 Apache 2.0 许可获得了许可。有关详情,请参阅 Google 开发者网站政策。Java 是 Oracle 和/或其关联公司的注册商标。
最后更新时间 (UTC):2024-11-26。
[null,null,["最后更新时间 (UTC):2024-11-26。"],[[["This guide outlines the process of setting up a Ruby gRPC server using a provided service definition."],["Users will need to install required gems, generate Ruby libraries from the service definition, and implement the server logic."],["Testing can be done initially without TLS, but production environments require configuring certificates for secure communication."],["The final setup involves organizing certificates and generated libraries within a specific directory structure for the server to function properly."],["Obtaining and updating trusted root certificates for client authentication are crucial steps for production deployment."]]],["The implementation requires the `google-protobuf` and `grpc` gems. Download the service definition, create the specified directory structure, and generate Ruby libraries using `grpc_tools_ruby_protoc`. TLS can be initially disabled using `--disable_tls` for testing. Production requires `server.pem`, `server.key`, and `trusted_client_roots.pem` within the certificates directory for TLS. The `trusted_client_roots.pem` may come from an authority like Mozilla or Google Internet Authority G2.\n"]]