Batch push websocket to improve performance

This commit is contained in:
LittleSheep 2024-07-17 11:58:51 +08:00
parent d97837dab6
commit 96b96912ed
11 changed files with 200 additions and 230 deletions

View File

@ -1,38 +0,0 @@
package grpc
import (
"context"
"git.solsynth.dev/hydrogen/dealer/pkg/hyper"
"git.solsynth.dev/hydrogen/dealer/pkg/proto"
"google.golang.org/grpc"
)
func (v *Server) Authenticate(ctx context.Context, request *proto.AuthRequest) (*proto.AuthReply, error) {
return forwardInvokeRequest(
hyper.ServiceTypeAuthProvider,
func(ctx context.Context, conn *grpc.ClientConn) (*proto.AuthReply, error) {
out, err := proto.NewAuthClient(conn).Authenticate(ctx, request)
return out, err
},
)
}
func (v *Server) EnsurePermGranted(ctx context.Context, request *proto.CheckPermRequest) (*proto.CheckPermResponse, error) {
return forwardInvokeRequest(
hyper.ServiceTypeAuthProvider,
func(ctx context.Context, conn *grpc.ClientConn) (*proto.CheckPermResponse, error) {
out, err := proto.NewAuthClient(conn).EnsurePermGranted(ctx, request)
return out, err
},
)
}
func (v *Server) EnsureUserPermGranted(ctx context.Context, request *proto.CheckUserPermRequest) (*proto.CheckUserPermResponse, error) {
return forwardInvokeRequest(
hyper.ServiceTypeAuthProvider,
func(ctx context.Context, conn *grpc.ClientConn) (*proto.CheckUserPermResponse, error) {
out, err := proto.NewAuthClient(conn).EnsureUserPermGranted(ctx, request)
return out, err
},
)
}

View File

@ -1,28 +0,0 @@
package grpc
import (
"context"
"fmt"
"git.solsynth.dev/hydrogen/dealer/pkg/hyper"
"git.solsynth.dev/hydrogen/dealer/pkg/internal/directory"
"google.golang.org/grpc"
"time"
)
func forwardInvokeRequest[T any](serviceType string, executor func(context.Context, *grpc.ClientConn) (T, error)) (T, error) {
var emptyResult T
instance := directory.GetServiceInstance(serviceType)
if instance == nil {
return emptyResult, fmt.Errorf("no available service %s found", hyper.ServiceTypeAuthProvider)
}
conn, err := instance.GetGrpcConn()
if err != nil {
return emptyResult, fmt.Errorf("service is down: %v", err)
}
ctx, cancel := context.WithTimeout(context.Background(), time.Second*5)
defer cancel()
return executor(ctx, conn)
}

View File

@ -1,28 +0,0 @@
package grpc
import (
"context"
"git.solsynth.dev/hydrogen/dealer/pkg/hyper"
"git.solsynth.dev/hydrogen/dealer/pkg/proto"
"google.golang.org/grpc"
)
func (v *Server) NotifyUser(ctx context.Context, request *proto.NotifyUserRequest) (*proto.NotifyResponse, error) {
return forwardInvokeRequest(
hyper.ServiceTypeAuthProvider,
func(ctx context.Context, conn *grpc.ClientConn) (*proto.NotifyResponse, error) {
out, err := proto.NewNotifierClient(conn).NotifyUser(ctx, request)
return out, err
},
)
}
func (v *Server) NotifyAllUser(ctx context.Context, request *proto.NotifyRequest) (*proto.NotifyResponse, error) {
return forwardInvokeRequest(
hyper.ServiceTypeAuthProvider,
func(ctx context.Context, conn *grpc.ClientConn) (*proto.NotifyResponse, error) {
out, err := proto.NewNotifierClient(conn).NotifyAllUser(ctx, request)
return out, err
},
)
}

View File

@ -1,78 +0,0 @@
package grpc
import (
"context"
"git.solsynth.dev/hydrogen/dealer/pkg/hyper"
"git.solsynth.dev/hydrogen/dealer/pkg/proto"
"google.golang.org/grpc"
)
func (v *Server) ListCommunityRealm(ctx context.Context, request *proto.ListRealmRequest) (*proto.ListRealmResponse, error) {
return forwardInvokeRequest(
hyper.ServiceTypeAuthProvider,
func(ctx context.Context, conn *grpc.ClientConn) (*proto.ListRealmResponse, error) {
out, err := proto.NewRealmClient(conn).ListCommunityRealm(ctx, request)
return out, err
},
)
}
func (v *Server) ListAvailableRealm(ctx context.Context, request *proto.LookupUserRealmRequest) (*proto.ListRealmResponse, error) {
return forwardInvokeRequest(
hyper.ServiceTypeAuthProvider,
func(ctx context.Context, conn *grpc.ClientConn) (*proto.ListRealmResponse, error) {
out, err := proto.NewRealmClient(conn).ListAvailableRealm(ctx, request)
return out, err
},
)
}
func (v *Server) ListOwnedRealm(ctx context.Context, request *proto.LookupUserRealmRequest) (*proto.ListRealmResponse, error) {
return forwardInvokeRequest(
hyper.ServiceTypeAuthProvider,
func(ctx context.Context, conn *grpc.ClientConn) (*proto.ListRealmResponse, error) {
out, err := proto.NewRealmClient(conn).ListOwnedRealm(ctx, request)
return out, err
},
)
}
func (v *Server) GetRealm(ctx context.Context, request *proto.LookupRealmRequest) (*proto.RealmInfo, error) {
return forwardInvokeRequest(
hyper.ServiceTypeAuthProvider,
func(ctx context.Context, conn *grpc.ClientConn) (*proto.RealmInfo, error) {
out, err := proto.NewRealmClient(conn).GetRealm(ctx, request)
return out, err
},
)
}
func (v *Server) ListRealmMember(ctx context.Context, request *proto.RealmMemberLookupRequest) (*proto.ListRealmMemberResponse, error) {
return forwardInvokeRequest(
hyper.ServiceTypeAuthProvider,
func(ctx context.Context, conn *grpc.ClientConn) (*proto.ListRealmMemberResponse, error) {
out, err := proto.NewRealmClient(conn).ListRealmMember(ctx, request)
return out, err
},
)
}
func (v *Server) GetRealmMember(ctx context.Context, request *proto.RealmMemberLookupRequest) (*proto.RealmMemberInfo, error) {
return forwardInvokeRequest(
hyper.ServiceTypeAuthProvider,
func(ctx context.Context, conn *grpc.ClientConn) (*proto.RealmMemberInfo, error) {
out, err := proto.NewRealmClient(conn).GetRealmMember(ctx, request)
return out, err
},
)
}
func (v *Server) CheckRealmMemberPerm(ctx context.Context, request *proto.CheckRealmPermRequest) (*proto.CheckRealmPermResponse, error) {
return forwardInvokeRequest(
hyper.ServiceTypeAuthProvider,
func(ctx context.Context, conn *grpc.ClientConn) (*proto.CheckRealmPermResponse, error) {
out, err := proto.NewRealmClient(conn).CheckRealmMemberPerm(ctx, request)
return out, err
},
)
}

View File

@ -1,18 +0,0 @@
package grpc
import (
"context"
"git.solsynth.dev/hydrogen/dealer/pkg/hyper"
"git.solsynth.dev/hydrogen/dealer/pkg/proto"
"google.golang.org/grpc"
)
func (v *Server) RecordEvent(ctx context.Context, request *proto.RecordEventRequest) (*proto.RecordEventResponse, error) {
return forwardInvokeRequest(
hyper.ServiceTypeAuthProvider,
func(ctx context.Context, conn *grpc.ClientConn) (*proto.RecordEventResponse, error) {
out, err := proto.NewEventRecorderClient(conn).RecordEvent(ctx, request)
return out, err
},
)
}

View File

@ -16,9 +16,6 @@ import (
type Server struct {
proto.UnimplementedServiceDirectoryServer
proto.UnimplementedStreamControllerServer
proto.UnimplementedEventRecorderServer
proto.UnimplementedNotifierServer
proto.UnimplementedRealmServer
proto.UnimplementedAuthServer
srv *grpc.Server
@ -31,9 +28,6 @@ func NewServer() *Server {
proto.RegisterServiceDirectoryServer(server.srv, server)
proto.RegisterStreamControllerServer(server.srv, server)
proto.RegisterEventRecorderServer(server.srv, server)
proto.RegisterNotifierServer(server.srv, server)
proto.RegisterRealmServer(server.srv, server)
proto.RegisterAuthServer(server.srv, server)
health.RegisterHealthServer(server.srv, server)

View File

@ -3,8 +3,10 @@ package grpc
import (
"context"
"fmt"
"git.solsynth.dev/hydrogen/dealer/pkg/internal/services"
"git.solsynth.dev/hydrogen/dealer/pkg/proto"
"github.com/samber/lo"
)
func (v *Server) CountStreamConnection(ctx context.Context, request *proto.CountConnectionRequest) (*proto.CountConnectionResponse, error) {
@ -34,3 +36,29 @@ func (v *Server) PushStream(ctx context.Context, request *proto.PushStreamReques
FailedCount: int64(cnt - success),
}, nil
}
func (v *Server) PushStreamBatch(ctx context.Context, request *proto.PushStreamBatchRequest) (*proto.PushStreamResponse, error) {
cnt, success, errs := services.WebsocketPushBatch(
lo.Map(request.GetUserId(), func(item uint64, idx int) uint {
return uint(item)
},
), request.GetBody(),
)
if len(errs) > 0 {
// Partial fail
return &proto.PushStreamResponse{
IsAllSuccess: false,
AffectedCount: int64(success),
FailedCount: int64(cnt - success),
}, nil
} else if cnt > 0 && success == 0 {
// All fail
return nil, fmt.Errorf("all push request failed: %v", errs)
}
return &proto.PushStreamResponse{
IsAllSuccess: true,
AffectedCount: int64(success),
FailedCount: int64(cnt - success),
}, nil
}

View File

@ -1,9 +1,10 @@
package services
import (
"sync"
"git.solsynth.dev/hydrogen/dealer/pkg/internal/models"
"github.com/gofiber/contrib/websocket"
"sync"
)
var (
@ -44,3 +45,17 @@ func WebsocketPush(uid uint, body []byte) (count int, success int, errs []error)
}
return
}
func WebsocketPushBatch(uidList []uint, body []byte) (count int, success int, errs []error) {
for _, uid := range uidList {
for conn := range wsConn[uid] {
if err := conn.WriteMessage(1, body); err != nil {
errs = append(errs, err)
} else {
success++
}
count++
}
}
return
}

View File

@ -169,6 +169,61 @@ func (x *PushStreamRequest) GetBody() []byte {
return nil
}
type PushStreamBatchRequest struct {
state protoimpl.MessageState
sizeCache protoimpl.SizeCache
unknownFields protoimpl.UnknownFields
UserId []uint64 `protobuf:"varint,1,rep,packed,name=user_id,json=userId,proto3" json:"user_id,omitempty"`
Body []byte `protobuf:"bytes,2,opt,name=body,proto3" json:"body,omitempty"`
}
func (x *PushStreamBatchRequest) Reset() {
*x = PushStreamBatchRequest{}
if protoimpl.UnsafeEnabled {
mi := &file_stream_proto_msgTypes[3]
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
ms.StoreMessageInfo(mi)
}
}
func (x *PushStreamBatchRequest) String() string {
return protoimpl.X.MessageStringOf(x)
}
func (*PushStreamBatchRequest) ProtoMessage() {}
func (x *PushStreamBatchRequest) ProtoReflect() protoreflect.Message {
mi := &file_stream_proto_msgTypes[3]
if protoimpl.UnsafeEnabled && x != nil {
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
if ms.LoadMessageInfo() == nil {
ms.StoreMessageInfo(mi)
}
return ms
}
return mi.MessageOf(x)
}
// Deprecated: Use PushStreamBatchRequest.ProtoReflect.Descriptor instead.
func (*PushStreamBatchRequest) Descriptor() ([]byte, []int) {
return file_stream_proto_rawDescGZIP(), []int{3}
}
func (x *PushStreamBatchRequest) GetUserId() []uint64 {
if x != nil {
return x.UserId
}
return nil
}
func (x *PushStreamBatchRequest) GetBody() []byte {
if x != nil {
return x.Body
}
return nil
}
type PushStreamResponse struct {
state protoimpl.MessageState
sizeCache protoimpl.SizeCache
@ -182,7 +237,7 @@ type PushStreamResponse struct {
func (x *PushStreamResponse) Reset() {
*x = PushStreamResponse{}
if protoimpl.UnsafeEnabled {
mi := &file_stream_proto_msgTypes[3]
mi := &file_stream_proto_msgTypes[4]
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
ms.StoreMessageInfo(mi)
}
@ -195,7 +250,7 @@ func (x *PushStreamResponse) String() string {
func (*PushStreamResponse) ProtoMessage() {}
func (x *PushStreamResponse) ProtoReflect() protoreflect.Message {
mi := &file_stream_proto_msgTypes[3]
mi := &file_stream_proto_msgTypes[4]
if protoimpl.UnsafeEnabled && x != nil {
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
if ms.LoadMessageInfo() == nil {
@ -208,7 +263,7 @@ func (x *PushStreamResponse) ProtoReflect() protoreflect.Message {
// Deprecated: Use PushStreamResponse.ProtoReflect.Descriptor instead.
func (*PushStreamResponse) Descriptor() ([]byte, []int) {
return file_stream_proto_rawDescGZIP(), []int{3}
return file_stream_proto_rawDescGZIP(), []int{4}
}
func (x *PushStreamResponse) GetIsAllSuccess() bool {
@ -246,28 +301,37 @@ var file_stream_proto_rawDesc = []byte{
0x68, 0x53, 0x74, 0x72, 0x65, 0x61, 0x6d, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x17,
0x0a, 0x07, 0x75, 0x73, 0x65, 0x72, 0x5f, 0x69, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x04, 0x52,
0x06, 0x75, 0x73, 0x65, 0x72, 0x49, 0x64, 0x12, 0x12, 0x0a, 0x04, 0x62, 0x6f, 0x64, 0x79, 0x18,
0x02, 0x20, 0x01, 0x28, 0x0c, 0x52, 0x04, 0x62, 0x6f, 0x64, 0x79, 0x22, 0x84, 0x01, 0x0a, 0x12,
0x50, 0x75, 0x73, 0x68, 0x53, 0x74, 0x72, 0x65, 0x61, 0x6d, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e,
0x73, 0x65, 0x12, 0x24, 0x0a, 0x0e, 0x69, 0x73, 0x5f, 0x61, 0x6c, 0x6c, 0x5f, 0x73, 0x75, 0x63,
0x63, 0x65, 0x73, 0x73, 0x18, 0x01, 0x20, 0x01, 0x28, 0x08, 0x52, 0x0c, 0x69, 0x73, 0x41, 0x6c,
0x6c, 0x53, 0x75, 0x63, 0x63, 0x65, 0x73, 0x73, 0x12, 0x25, 0x0a, 0x0e, 0x61, 0x66, 0x66, 0x65,
0x63, 0x74, 0x65, 0x64, 0x5f, 0x63, 0x6f, 0x75, 0x6e, 0x74, 0x18, 0x02, 0x20, 0x01, 0x28, 0x03,
0x52, 0x0d, 0x61, 0x66, 0x66, 0x65, 0x63, 0x74, 0x65, 0x64, 0x43, 0x6f, 0x75, 0x6e, 0x74, 0x12,
0x21, 0x0a, 0x0c, 0x66, 0x61, 0x69, 0x6c, 0x65, 0x64, 0x5f, 0x63, 0x6f, 0x75, 0x6e, 0x74, 0x18,
0x03, 0x20, 0x01, 0x28, 0x03, 0x52, 0x0b, 0x66, 0x61, 0x69, 0x6c, 0x65, 0x64, 0x43, 0x6f, 0x75,
0x6e, 0x74, 0x32, 0xb1, 0x01, 0x0a, 0x10, 0x53, 0x74, 0x72, 0x65, 0x61, 0x6d, 0x43, 0x6f, 0x6e,
0x74, 0x72, 0x6f, 0x6c, 0x6c, 0x65, 0x72, 0x12, 0x58, 0x0a, 0x15, 0x43, 0x6f, 0x75, 0x6e, 0x74,
0x53, 0x74, 0x72, 0x65, 0x61, 0x6d, 0x43, 0x6f, 0x6e, 0x6e, 0x65, 0x63, 0x74, 0x69, 0x6f, 0x6e,
0x12, 0x1d, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2e, 0x43, 0x6f, 0x75, 0x6e, 0x74, 0x43, 0x6f,
0x6e, 0x6e, 0x65, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a,
0x1e, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2e, 0x43, 0x6f, 0x75, 0x6e, 0x74, 0x43, 0x6f, 0x6e,
0x6e, 0x65, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22,
0x00, 0x12, 0x43, 0x0a, 0x0a, 0x50, 0x75, 0x73, 0x68, 0x53, 0x74, 0x72, 0x65, 0x61, 0x6d, 0x12,
0x18, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2e, 0x50, 0x75, 0x73, 0x68, 0x53, 0x74, 0x72, 0x65,
0x61, 0x6d, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x19, 0x2e, 0x70, 0x72, 0x6f, 0x74,
0x6f, 0x2e, 0x50, 0x75, 0x73, 0x68, 0x53, 0x74, 0x72, 0x65, 0x61, 0x6d, 0x52, 0x65, 0x73, 0x70,
0x6f, 0x6e, 0x73, 0x65, 0x22, 0x00, 0x42, 0x09, 0x5a, 0x07, 0x2e, 0x3b, 0x70, 0x72, 0x6f, 0x74,
0x6f, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33,
0x02, 0x20, 0x01, 0x28, 0x0c, 0x52, 0x04, 0x62, 0x6f, 0x64, 0x79, 0x22, 0x45, 0x0a, 0x16, 0x50,
0x75, 0x73, 0x68, 0x53, 0x74, 0x72, 0x65, 0x61, 0x6d, 0x42, 0x61, 0x74, 0x63, 0x68, 0x52, 0x65,
0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x17, 0x0a, 0x07, 0x75, 0x73, 0x65, 0x72, 0x5f, 0x69, 0x64,
0x18, 0x01, 0x20, 0x03, 0x28, 0x04, 0x52, 0x06, 0x75, 0x73, 0x65, 0x72, 0x49, 0x64, 0x12, 0x12,
0x0a, 0x04, 0x62, 0x6f, 0x64, 0x79, 0x18, 0x02, 0x20, 0x01, 0x28, 0x0c, 0x52, 0x04, 0x62, 0x6f,
0x64, 0x79, 0x22, 0x84, 0x01, 0x0a, 0x12, 0x50, 0x75, 0x73, 0x68, 0x53, 0x74, 0x72, 0x65, 0x61,
0x6d, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x24, 0x0a, 0x0e, 0x69, 0x73, 0x5f,
0x61, 0x6c, 0x6c, 0x5f, 0x73, 0x75, 0x63, 0x63, 0x65, 0x73, 0x73, 0x18, 0x01, 0x20, 0x01, 0x28,
0x08, 0x52, 0x0c, 0x69, 0x73, 0x41, 0x6c, 0x6c, 0x53, 0x75, 0x63, 0x63, 0x65, 0x73, 0x73, 0x12,
0x25, 0x0a, 0x0e, 0x61, 0x66, 0x66, 0x65, 0x63, 0x74, 0x65, 0x64, 0x5f, 0x63, 0x6f, 0x75, 0x6e,
0x74, 0x18, 0x02, 0x20, 0x01, 0x28, 0x03, 0x52, 0x0d, 0x61, 0x66, 0x66, 0x65, 0x63, 0x74, 0x65,
0x64, 0x43, 0x6f, 0x75, 0x6e, 0x74, 0x12, 0x21, 0x0a, 0x0c, 0x66, 0x61, 0x69, 0x6c, 0x65, 0x64,
0x5f, 0x63, 0x6f, 0x75, 0x6e, 0x74, 0x18, 0x03, 0x20, 0x01, 0x28, 0x03, 0x52, 0x0b, 0x66, 0x61,
0x69, 0x6c, 0x65, 0x64, 0x43, 0x6f, 0x75, 0x6e, 0x74, 0x32, 0x80, 0x02, 0x0a, 0x10, 0x53, 0x74,
0x72, 0x65, 0x61, 0x6d, 0x43, 0x6f, 0x6e, 0x74, 0x72, 0x6f, 0x6c, 0x6c, 0x65, 0x72, 0x12, 0x58,
0x0a, 0x15, 0x43, 0x6f, 0x75, 0x6e, 0x74, 0x53, 0x74, 0x72, 0x65, 0x61, 0x6d, 0x43, 0x6f, 0x6e,
0x6e, 0x65, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x12, 0x1d, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2e,
0x43, 0x6f, 0x75, 0x6e, 0x74, 0x43, 0x6f, 0x6e, 0x6e, 0x65, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x52,
0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x1e, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2e, 0x43,
0x6f, 0x75, 0x6e, 0x74, 0x43, 0x6f, 0x6e, 0x6e, 0x65, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x52, 0x65,
0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, 0x00, 0x12, 0x43, 0x0a, 0x0a, 0x50, 0x75, 0x73, 0x68,
0x53, 0x74, 0x72, 0x65, 0x61, 0x6d, 0x12, 0x18, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2e, 0x50,
0x75, 0x73, 0x68, 0x53, 0x74, 0x72, 0x65, 0x61, 0x6d, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74,
0x1a, 0x19, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2e, 0x50, 0x75, 0x73, 0x68, 0x53, 0x74, 0x72,
0x65, 0x61, 0x6d, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, 0x00, 0x12, 0x4d, 0x0a,
0x0f, 0x50, 0x75, 0x73, 0x68, 0x53, 0x74, 0x72, 0x65, 0x61, 0x6d, 0x42, 0x61, 0x74, 0x63, 0x68,
0x12, 0x1d, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2e, 0x50, 0x75, 0x73, 0x68, 0x53, 0x74, 0x72,
0x65, 0x61, 0x6d, 0x42, 0x61, 0x74, 0x63, 0x68, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a,
0x19, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2e, 0x50, 0x75, 0x73, 0x68, 0x53, 0x74, 0x72, 0x65,
0x61, 0x6d, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, 0x00, 0x42, 0x09, 0x5a, 0x07,
0x2e, 0x3b, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33,
}
var (
@ -282,20 +346,23 @@ func file_stream_proto_rawDescGZIP() []byte {
return file_stream_proto_rawDescData
}
var file_stream_proto_msgTypes = make([]protoimpl.MessageInfo, 4)
var file_stream_proto_msgTypes = make([]protoimpl.MessageInfo, 5)
var file_stream_proto_goTypes = []any{
(*CountConnectionRequest)(nil), // 0: proto.CountConnectionRequest
(*CountConnectionResponse)(nil), // 1: proto.CountConnectionResponse
(*PushStreamRequest)(nil), // 2: proto.PushStreamRequest
(*PushStreamResponse)(nil), // 3: proto.PushStreamResponse
(*PushStreamBatchRequest)(nil), // 3: proto.PushStreamBatchRequest
(*PushStreamResponse)(nil), // 4: proto.PushStreamResponse
}
var file_stream_proto_depIdxs = []int32{
0, // 0: proto.StreamController.CountStreamConnection:input_type -> proto.CountConnectionRequest
2, // 1: proto.StreamController.PushStream:input_type -> proto.PushStreamRequest
1, // 2: proto.StreamController.CountStreamConnection:output_type -> proto.CountConnectionResponse
3, // 3: proto.StreamController.PushStream:output_type -> proto.PushStreamResponse
2, // [2:4] is the sub-list for method output_type
0, // [0:2] is the sub-list for method input_type
3, // 2: proto.StreamController.PushStreamBatch:input_type -> proto.PushStreamBatchRequest
1, // 3: proto.StreamController.CountStreamConnection:output_type -> proto.CountConnectionResponse
4, // 4: proto.StreamController.PushStream:output_type -> proto.PushStreamResponse
4, // 5: proto.StreamController.PushStreamBatch:output_type -> proto.PushStreamResponse
3, // [3:6] is the sub-list for method output_type
0, // [0:3] is the sub-list for method input_type
0, // [0:0] is the sub-list for extension type_name
0, // [0:0] is the sub-list for extension extendee
0, // [0:0] is the sub-list for field type_name
@ -344,6 +411,18 @@ func file_stream_proto_init() {
}
}
file_stream_proto_msgTypes[3].Exporter = func(v any, i int) any {
switch v := v.(*PushStreamBatchRequest); i {
case 0:
return &v.state
case 1:
return &v.sizeCache
case 2:
return &v.unknownFields
default:
return nil
}
}
file_stream_proto_msgTypes[4].Exporter = func(v any, i int) any {
switch v := v.(*PushStreamResponse); i {
case 0:
return &v.state
@ -362,7 +441,7 @@ func file_stream_proto_init() {
GoPackagePath: reflect.TypeOf(x{}).PkgPath(),
RawDescriptor: file_stream_proto_rawDesc,
NumEnums: 0,
NumMessages: 4,
NumMessages: 5,
NumExtensions: 0,
NumServices: 1,
},

View File

@ -7,6 +7,7 @@ package proto;
service StreamController {
rpc CountStreamConnection(CountConnectionRequest) returns (CountConnectionResponse) {}
rpc PushStream(PushStreamRequest) returns (PushStreamResponse) {}
rpc PushStreamBatch(PushStreamBatchRequest) returns (PushStreamResponse) {}
}
message CountConnectionRequest {
@ -22,8 +23,13 @@ message PushStreamRequest {
bytes body = 2;
}
message PushStreamBatchRequest {
repeated uint64 user_id = 1;
bytes body = 2;
}
message PushStreamResponse {
bool is_all_success = 1;
int64 affected_count = 2;
int64 failed_count = 3;
}
}

View File

@ -21,6 +21,7 @@ const _ = grpc.SupportPackageIsVersion8
const (
StreamController_CountStreamConnection_FullMethodName = "/proto.StreamController/CountStreamConnection"
StreamController_PushStream_FullMethodName = "/proto.StreamController/PushStream"
StreamController_PushStreamBatch_FullMethodName = "/proto.StreamController/PushStreamBatch"
)
// StreamControllerClient is the client API for StreamController service.
@ -29,6 +30,7 @@ const (
type StreamControllerClient interface {
CountStreamConnection(ctx context.Context, in *CountConnectionRequest, opts ...grpc.CallOption) (*CountConnectionResponse, error)
PushStream(ctx context.Context, in *PushStreamRequest, opts ...grpc.CallOption) (*PushStreamResponse, error)
PushStreamBatch(ctx context.Context, in *PushStreamBatchRequest, opts ...grpc.CallOption) (*PushStreamResponse, error)
}
type streamControllerClient struct {
@ -59,12 +61,23 @@ func (c *streamControllerClient) PushStream(ctx context.Context, in *PushStreamR
return out, nil
}
func (c *streamControllerClient) PushStreamBatch(ctx context.Context, in *PushStreamBatchRequest, opts ...grpc.CallOption) (*PushStreamResponse, error) {
cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...)
out := new(PushStreamResponse)
err := c.cc.Invoke(ctx, StreamController_PushStreamBatch_FullMethodName, in, out, cOpts...)
if err != nil {
return nil, err
}
return out, nil
}
// StreamControllerServer is the server API for StreamController service.
// All implementations must embed UnimplementedStreamControllerServer
// for forward compatibility
type StreamControllerServer interface {
CountStreamConnection(context.Context, *CountConnectionRequest) (*CountConnectionResponse, error)
PushStream(context.Context, *PushStreamRequest) (*PushStreamResponse, error)
PushStreamBatch(context.Context, *PushStreamBatchRequest) (*PushStreamResponse, error)
mustEmbedUnimplementedStreamControllerServer()
}
@ -78,6 +91,9 @@ func (UnimplementedStreamControllerServer) CountStreamConnection(context.Context
func (UnimplementedStreamControllerServer) PushStream(context.Context, *PushStreamRequest) (*PushStreamResponse, error) {
return nil, status.Errorf(codes.Unimplemented, "method PushStream not implemented")
}
func (UnimplementedStreamControllerServer) PushStreamBatch(context.Context, *PushStreamBatchRequest) (*PushStreamResponse, error) {
return nil, status.Errorf(codes.Unimplemented, "method PushStreamBatch not implemented")
}
func (UnimplementedStreamControllerServer) mustEmbedUnimplementedStreamControllerServer() {}
// UnsafeStreamControllerServer may be embedded to opt out of forward compatibility for this service.
@ -127,6 +143,24 @@ func _StreamController_PushStream_Handler(srv interface{}, ctx context.Context,
return interceptor(ctx, in, info, handler)
}
func _StreamController_PushStreamBatch_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
in := new(PushStreamBatchRequest)
if err := dec(in); err != nil {
return nil, err
}
if interceptor == nil {
return srv.(StreamControllerServer).PushStreamBatch(ctx, in)
}
info := &grpc.UnaryServerInfo{
Server: srv,
FullMethod: StreamController_PushStreamBatch_FullMethodName,
}
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
return srv.(StreamControllerServer).PushStreamBatch(ctx, req.(*PushStreamBatchRequest))
}
return interceptor(ctx, in, info, handler)
}
// StreamController_ServiceDesc is the grpc.ServiceDesc for StreamController service.
// It's only intended for direct use with grpc.RegisterService,
// and not to be introspected or modified (even as a copy)
@ -142,6 +176,10 @@ var StreamController_ServiceDesc = grpc.ServiceDesc{
MethodName: "PushStream",
Handler: _StreamController_PushStream_Handler,
},
{
MethodName: "PushStreamBatch",
Handler: _StreamController_PushStreamBatch_Handler,
},
},
Streams: []grpc.StreamDesc{},
Metadata: "stream.proto",