-
Notifications
You must be signed in to change notification settings - Fork 475
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Use protobuf only for RPC calls #18
Conversation
This will make it possible to create cluster and RPC libs for other programming languages
Pull Request Test Coverage Report for Build 191
💛 - Coveralls |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍 nice job
I like the idea of removing gob but as far as I understood these changes will also remove the ability of making RPC calls with more than one argument. Are we ok with this tradeoff?
@@ -91,7 +91,9 @@ func (a *Remote) Kick(ctx context.Context) error { | |||
if a.Session.UID() == "" { | |||
return constants.ErrNoUIDBind | |||
} | |||
b, err := util.GobEncode([]byte(a.Session.UID())) | |||
b, err := proto.Marshal(&protos.KickMsg{ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can't we just byte encode the string like this: []byte(a.Session.UID())
? or are you using a proto since you may wan't to send more data along with the ID?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
RPC must receive structs that implements proto.Message, a byte array doesn't
e2e/e2e_test.go
Outdated
@@ -57,10 +57,10 @@ func TestHandlerCallToFront(t *testing.T) { | |||
data []byte | |||
resp []byte | |||
}{ | |||
{"connector.testsvc.testrequestonlysessionreturnsptr", []byte(``), []byte(`{"code":200,"msg":"hello"}`)}, | |||
{"connector.testsvc.testrequestonlysessionreturnsptr", []byte(``), []byte(`{"Code":200,"Msg":"hello"}`)}, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we should keep our json keys as camel case
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is because of protobuf, more details below
@@ -50,8 +50,7 @@ func configureBackend() { | |||
|
|||
func configureFrontend(port int) { | |||
configureJaeger("connector") | |||
ws := acceptor.NewWSAcceptor(fmt.Sprintf(":%d", port)) | |||
tcp := acceptor.NewTCPAcceptor(fmt.Sprintf(":%d", port+1)) | |||
tcp := acceptor.NewTCPAcceptor(fmt.Sprintf(":%d", port)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why did you remove ws support? we're no longer accepting it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we didn't, it's just that we are not using the ws acceptor for nothing in this example
protos/pitaya.proto
Outdated
@@ -52,3 +52,16 @@ message Error { | |||
string msg = 2; | |||
map<string, string> metadata = 3; | |||
} | |||
|
|||
message KickMsg { | |||
string UserID = 1; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
userId
protos/pitaya.proto
Outdated
} | ||
|
||
message KickAnswer { | ||
bool Kicked = 1; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
kicked
protos/pitaya.proto
Outdated
} | ||
|
||
message BindMsg { | ||
string UID = 1; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
uid, fid
"github.com/topfreegames/pitaya/constants" | ||
"github.com/topfreegames/pitaya/route" | ||
) | ||
|
||
// RPC calls a method in a different server | ||
func RPC(ctx context.Context, routeStr string, reply interface{}, args ...interface{}) error { | ||
return doSendRPC(ctx, "", routeStr, reply, args...) | ||
func RPC(ctx context.Context, routeStr string, reply proto.Message, arg proto.Message) error { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we no longer accept RPC calls with several arguments?
This will make it possible to have servers made in other programming languages to send and receive RPC calls to go servers.