42 lines
1.6 KiB
Go
42 lines
1.6 KiB
Go
// Package grpc 将 im-service 领域能力适配成内部 protobuf gRPC 服务。
|
||
package grpc
|
||
|
||
import (
|
||
"context"
|
||
|
||
imv1 "hyapp/api/proto/im/v1"
|
||
imservice "hyapp/services/im-service/internal/service"
|
||
)
|
||
|
||
// Server 把 im-service 领域逻辑暴露成 gRPC RoomBridgeService。
|
||
type Server struct {
|
||
// UnimplementedRoomBridgeServiceServer 保持 protobuf 向前兼容,新 RPC 未实现时返回标准错误。
|
||
imv1.UnimplementedRoomBridgeServiceServer
|
||
|
||
// svc 是所有 RPC 的领域服务入口,gRPC 层不持有消息状态。
|
||
svc *imservice.Service
|
||
}
|
||
|
||
// NewServer 创建 gRPC server 适配器。
|
||
func NewServer(svc *imservice.Service) *Server {
|
||
return &Server{svc: svc}
|
||
}
|
||
|
||
// PublishRoomEvent 代理到领域服务。
|
||
func (s *Server) PublishRoomEvent(ctx context.Context, req *imv1.PublishRoomEventRequest) (*imv1.PublishRoomEventResponse, error) {
|
||
// room-service 通过该 RPC 做低时延房间系统事件广播;幂等由 service 层 event_id 表保证。
|
||
return s.svc.PublishRoomEvent(ctx, req)
|
||
}
|
||
|
||
// PushSystemNotice 代理到领域服务。
|
||
func (s *Server) PushSystemNotice(ctx context.Context, req *imv1.PushSystemNoticeRequest) (*imv1.PushSystemNoticeResponse, error) {
|
||
// 系统通知面向用户维度投递,ACK 语义和单聊一致。
|
||
return s.svc.PushSystemNotice(ctx, req)
|
||
}
|
||
|
||
// ForceRoomResync 代理到领域服务。
|
||
func (s *Server) ForceRoomResync(ctx context.Context, req *imv1.ForceRoomResyncRequest) (*imv1.ForceRoomResyncResponse, error) {
|
||
// 恢复或接管场景下 room-service 可要求指定用户重新拉房间状态。
|
||
return s.svc.ForceRoomResync(ctx, req)
|
||
}
|