pitaya icon indicating copy to clipboard operation
pitaya copied to clipboard

cluster_grpc example error

Open CoreELEE opened this issue 2 years ago • 1 comments

room is a backend servers, Pitaya Doc

Backend sessions Backend sessions have access to the sessions through the handler’s methods, but they have some limitations and special characteristics. Changes to session variables must be pushed to the frontend server by calling s.PushToFront (this is not needed for s.Bind operations), setting callbacks to session lifecycle operations is also not allowed. One can also not retrieve a session by user ID from a backend server.

In the examples/demo/cluster_grpc/services/room.go

// Join room func (r *Room) Join(ctx context.Context) (*JoinResponse, error) { s := r.app.GetSessionFromCtx(ctx) err := r.app.GroupAddMember(ctx, "room", s.UID()) if err != nil { return nil, err } members, err := r.app.GroupMembers(ctx, "room") if err != nil { return nil, err } s.Push("onMembers", &AllMembers{Members: members}) r.app.GroupBroadcast(ctx, "connector", "room", "onNewUser", &NewUser{Content: fmt.Sprintf("New user: %d", s.ID())}) err = s.OnClose(func() { r.app.GroupRemoveMember(ctx, "room", s.UID()) }) if err != nil { return nil, err } return &JoinResponse{Result: "success"}, nil }

s.OnCloseThis will cause an error. {"code":"PIT-000","msg":"onclose callbacks are not allowed on backend servers"}

CoreELEE avatar Oct 12 '23 08:10 CoreELEE

This is indeed a bug in the demo, probably a case of copy-paste, which the author has not run

lyh1091106900 avatar Oct 23 '23 04:10 lyh1091106900

GRPC is being deprecated in the newer releases. ETCD has proven a better mechanism for pitaya RPC

felipejfc avatar Aug 13 '24 12:08 felipejfc