1, 安装ruby-protobuf
gem install ruby_protobuf
2, 定义rpc service的rpc.proto文件
package demo;
message SearchRequest {
required string keyword = 1;
}
message SearchResponse {
required string result = 1;
}
service RpcService {
rpc Search (SearchRequest) returns (SearchResponse);
}
3, 编译
rprotoc rpc.proto
4, 完成service和client代码
rpc_service.rb
require 'protobuf/rpc/server'
require 'protobuf/rpc/handler'
require 'rpc.pb'
class Demo::SearchHandler < Protobuf::Rpc::Handler
request Demo::SearchRequest
response Demo::SearchResponse
def self.process_request(request, response)
if request.keyword == 'google'
response.result = 'www.google.com'
elsif request.keyword == 'freewheel'
response.result = 'www.freewheel.tv'
else
response.result = ''
end
end
end
class Demo::RpcService < Protobuf::Rpc::Server
def setup_handlers
@handlers = {
:search => Demo::SearchHandler,
}
end
end
client_search.rb
#!/usr/bin/env ruby
require 'protobuf/rpc/client'
require 'rpc.pb'
# build request
request1 = Demo::SearchRequest.new
request1.keyword = 'google'
request2 = Demo::SearchRequest.new
request2.keyword = 'freewheel'
# create blunk response
response1 = Demo::SearchResponse.new
response2 = Demo::SearchResponse.new
# execute rpc
Protobuf::Rpc::Client.new('localhost', 9999).call :search, request1, response1
Protobuf::Rpc::Client.new('localhost', 9999).call :search, request2, response2
p response1.result
p response2.result
5, 运行
启动Service
ruby start_rpc_service
// :port参数名改为:Port
调用Client
ruby client_search.rb
// result
"www.google.com"
"www.freewheel.tv"
分享到:
相关推荐
赠送jar包:activemq-protobuf-1.1.jar; 赠送原API文档:activemq-protobuf-1.1-javadoc.jar; 赠送源代码:activemq-protobuf-1.1-sources.jar; 包含翻译后的API文档:activemq-protobuf-1.1-javadoc-API文档-...
activemq-protobuf-1.1.jar;activemq-protobuf-1.1.jar
赠送jar包:grpc-protobuf-1.24.0.jar; 赠送原API文档:grpc-protobuf-1.24.0-javadoc.jar; 赠送源代码:grpc-protobuf-1.24.0-sources.jar; 赠送Maven依赖信息文件:grpc-protobuf-1.24.0.pom; 包含翻译后的API...
赠送jar包:grpc-protobuf-1.24.0.jar; 赠送原API文档:grpc-protobuf-1.24.0-javadoc.jar; 赠送源代码:grpc-protobuf-1.24.0-sources.jar; 赠送Maven依赖信息文件:grpc-protobuf-1.24.0.pom; 包含翻译后的API...
赠送jar包:activemq-protobuf-1.1.jar; 赠送原API文档:activemq-protobuf-1.1-javadoc.jar; 赠送源代码:activemq-protobuf-1.1-sources.jar; 包含翻译后的API文档:activemq-protobuf-1.1-javadoc-API文档-...
标签:activemq-protobuf-test-1.1.jar,activemq,protobuf,test,1.1,jar包下载,依赖包
赠送jar包:akka-protobuf_2.11-2.4.20.jar; 赠送原API文档:akka-protobuf_2.11-2.4.20-javadoc.jar; 赠送源代码:akka-protobuf_2.11-2.4.20-sources.jar; 赠送Maven依赖信息文件:akka-protobuf_2.11-2.4.20....
赠送jar包:akka-protobuf_2.11-2.4.20.jar; 赠送原API文档:akka-protobuf_2.11-2.4.20-javadoc.jar; 赠送源代码:akka-protobuf_2.11-2.4.20-sources.jar; 赠送Maven依赖信息文件:akka-protobuf_2.11-2.4.20....
标签:activemq-protobuf-pom-1.0-source-release.zip,activemq,protobuf,pom,1.0,source,release.zip包下载,依赖包
标签:activemq-protobuf-pom-1.1-source-release.tar.gz,activemq,protobuf,pom,1.1,source,release.tar.gz包下载,依赖包
PHP调用protobuf通信接口的使用示例,采用rpc通信。
X-Protobuf-Schema: src/main/proto/tutorial/addressbook.proto < X-Protobuf-Message: tutorial.Person < Content-Type: application/x-protobuf ; charset=UTF-8 < Content-Length:
在线protobuf编码/解码工具。 进入根目录,通过以下命令启动。 bower install serve
idea-plugin-protobuf 是 Intellij IDEA 的插件,用来实现对 Google Protocol Buffes 的支持。
开源项目-golang-protobuf.zip,改进go协议的建议。关于设计和迁移计划的反馈。
google-protobuf-java-2.6.1.jar 使用github下载的源码生成的jar包。
IntelliJ-Protobuf-Language-Plugin-1.7.0
开源项目-google-protobuf.zip,Release Protocol Buffers v3.0.0 路 google/protobuf 路 GitHub
IntelliJ-Protobuf-Language-Plugin-1.7.12