Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit d144dbd
Showing
11 changed files
with
200 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
--- | ||
BUNDLE_DISABLE_SHARED_GEMS: "1" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
|
||
gem 'ruby_protobuf', path: '/code/src/ruby-protobuf' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
PATH | ||
remote: /code/src/ruby-protobuf | ||
specs: | ||
ruby_protobuf (0.4.0.1) | ||
|
||
GEM | ||
specs: | ||
|
||
PLATFORMS | ||
ruby | ||
|
||
DEPENDENCIES | ||
ruby_protobuf! |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
require 'logger' | ||
|
||
$logger = Logger.new('server.log') | ||
$logger.level = Logger::DEBUG |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
### Generated by rprotoc. DO NOT EDIT! | ||
### <proto file: proto/user.proto> | ||
# package proto; | ||
# | ||
# message User { | ||
# optional string guid = 1; | ||
# } | ||
# | ||
# message UserList { | ||
# repeated User users = 1; | ||
# } | ||
# | ||
# message UserFindRequest { | ||
# repeated string guids = 1; | ||
# } | ||
# | ||
# service UserService { | ||
# rpc find (UserFindRequest) returns (UserList); | ||
# rpc create (User) returns (User); | ||
# } | ||
require 'protobuf/message/message' | ||
require 'protobuf/message/enum' | ||
require 'protobuf/message/service' | ||
require 'protobuf/message/extend' | ||
|
||
module Proto | ||
class User < ::Protobuf::Message | ||
defined_in __FILE__ | ||
optional :string, :guid, 1 | ||
end | ||
class UserList < ::Protobuf::Message | ||
defined_in __FILE__ | ||
repeated :User, :users, 1 | ||
end | ||
class UserFindRequest < ::Protobuf::Message | ||
defined_in __FILE__ | ||
repeated :string, :guids, 1 | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package proto; | ||
|
||
message User { | ||
optional string guid = 1; | ||
} | ||
|
||
message UserList { | ||
repeated User users = 1; | ||
} | ||
|
||
message UserFindRequest { | ||
repeated string guids = 1; | ||
} | ||
|
||
service UserService { | ||
rpc find (UserFindRequest) returns (UserList); | ||
rpc create (User) returns (User); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
require 'protobuf/rpc/service' | ||
require File.expand_path 'user.pb', File.dirname(__FILE__) | ||
|
||
## !! DO NOT EDIT THIS FILE !! | ||
## | ||
## To implement this service as defined by the protobuf, simply | ||
## reopen Proto::UserService and implement each service method: | ||
## | ||
## module Proto | ||
## class UserService | ||
## | ||
## # request -> Proto::UserFindRequest | ||
## # response -> Proto::UserList | ||
## def find | ||
## # TODO: implement find | ||
## end | ||
## | ||
## # request -> Proto::User | ||
## # response -> Proto::User | ||
## def create | ||
## # TODO: implement create | ||
## end | ||
## | ||
## end | ||
## end | ||
## | ||
|
||
module Proto | ||
class UserService < Protobuf::Rpc::Service | ||
rpc :find, UserFindRequest, UserList | ||
rpc :create, User, User | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
I, [2010-09-13T01:03:02.127050 #16747] INFO -- : WEBrick 1.3.1 | ||
I, [2010-09-13T01:03:02.127195 #16747] INFO -- : ruby 1.9.2 (2010-08-18) [x86_64-darwin10.4.0] | ||
D, [2010-09-13T01:03:02.127428 #16747] DEBUG -- : TCPServer.new(::, 9939) | ||
D, [2010-09-13T01:03:02.127585 #16747] DEBUG -- : TCPServer.new(0.0.0.0, 9939) | ||
I, [2010-09-13T01:03:26.906599 #16759] INFO -- : WEBrick 1.3.1 | ||
I, [2010-09-13T01:03:26.906729 #16759] INFO -- : ruby 1.9.2 (2010-08-18) [x86_64-darwin10.4.0] | ||
D, [2010-09-13T01:03:26.906976 #16759] DEBUG -- : TCPServer.new(::, 9939) | ||
D, [2010-09-13T01:03:26.907197 #16759] DEBUG -- : TCPServer.new(0.0.0.0, 9939) | ||
I, [2010-09-13T01:07:26.590746 #16869] INFO -- : [S] Setting up server | ||
I, [2010-09-13T01:07:26.591017 #16869] INFO -- : WEBrick 1.3.1 | ||
I, [2010-09-13T01:07:26.591099 #16869] INFO -- : ruby 1.9.2 (2010-08-18) [x86_64-darwin10.4.0] | ||
D, [2010-09-13T01:07:26.591268 #16869] DEBUG -- : TCPServer.new(::, 9939) | ||
D, [2010-09-13T01:07:26.591456 #16869] DEBUG -- : TCPServer.new(0.0.0.0, 9939) | ||
I, [2010-09-13T01:07:40.403557 #16877] INFO -- : [C] setting up client | ||
I, [2010-09-13T01:07:53.848583 #16883] INFO -- : [C] setting up client | ||
I, [2010-09-13T01:10:07.409560 #16952] INFO -- : [S] Setting up server | ||
I, [2010-09-13T01:10:07.409836 #16952] INFO -- : WEBrick 1.3.1 | ||
I, [2010-09-13T01:10:07.409916 #16952] INFO -- : ruby 1.9.2 (2010-08-18) [x86_64-darwin10.4.0] | ||
D, [2010-09-13T01:10:07.410084 #16952] DEBUG -- : TCPServer.new(::, 9939) | ||
D, [2010-09-13T01:10:07.410274 #16952] DEBUG -- : TCPServer.new(0.0.0.0, 9939) | ||
I, [2010-09-13T01:10:09.869319 #16953] INFO -- : [C] setting up client | ||
I, [2010-09-13T01:10:09.869501 #16953] INFO -- : [C] calling client.find | ||
E, [2010-09-13T01:10:09.872046 #16953] ERROR -- : Got client controller failure | ||
E, [2010-09-13T01:10:09.872138 #16953] ERROR -- : Response Error: Connection refused - connect(2) (Errno::ECONNREFUSED) (BAD_REQUEST_DATA) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
require './logger' | ||
require 'protobuf/rpc/server' | ||
|
||
$logger.info '[S] Setting up server' | ||
Protobuf::Rpc::Server.new Host: 'localhost', Port: 9939, Logger: $logger | ||
|
||
loop do | ||
p '.' | ||
sleep 10 | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
require 'protobuf/rpc/client' | ||
require './proto/user.pb' | ||
require './user_service' | ||
require './logger' | ||
|
||
$logger.info '[C] setting up client' | ||
client = Protobuf::Rpc::Client.new Proto::UserService, 'localhost', 9938 | ||
|
||
request = Proto::UserFindRequest.new.tap do |req| | ||
req.guids << 'USER_GUID_1' | ||
req.guids << 'USER_GUID_2' | ||
req.guids << 'USER_GUID_3' | ||
req.guids << 'USER_GUID_4' | ||
req.guids << 'USER_GUID_5' | ||
end | ||
|
||
$logger.info '[C] calling client.find' | ||
client.find request, Proto::UserList do |controller, response| | ||
if controller.failed? | ||
$logger.error 'Got client controller failure' | ||
$logger.error controller.error_message | ||
else | ||
$logger.info 'Got client OK response' | ||
response.users.each do |user| | ||
$logger.info 'user.guid = %s' % user.guid | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
require './proto/user.pb' | ||
require './proto/user_service' | ||
require './logger' | ||
|
||
module Proto | ||
class UserService | ||
|
||
# request -> Proto::UserFindRequest | ||
# response -> Proto::UserList | ||
def find | ||
$logger.info '[S] in Proto::UserService#find' | ||
response.users = request.guids.map do |guid| | ||
Proto::User.new.tap do |user| | ||
user.guid = guid | ||
end | ||
end | ||
end | ||
|
||
# request -> Proto::User | ||
# response -> Proto::User | ||
def create | ||
$logger.info '[S] in Proto::UserService#create' | ||
# TODO: implement create | ||
end | ||
|
||
end | ||
end |