feat(ws): implement WebSocket cluster mode with Redis Pub/Sub
Introduce a new WebSocket messaging architecture that supports both standalone and cluster modes. This allows for horizontal scaling of WebSocket servers by using Redis Pub/Sub to synchronize messages across multiple instances. Key changes: - Added `ws.MessagePublisher` interface to abstract message distribution. - Implemented `ws.Bus` to handle cluster-mode messaging via Redis. - Added `ws.OnlineTracker` to manage user online status across the cluster. - Refactored multiple services (Chat, Group, Push, Call, etc.) to use the new `MessagePublisher` instead of a concrete `ws.Hub`. - Added WebSocket configuration options (mode, instance ID, channel, TTL, heartbeat) to `config.yaml` and `config.go`. - Updated dependency injection with Wire to support the new publisher and Redis client. - Improved logging by replacing standard `log` with `zap` in several service components.
This commit is contained in:
@@ -63,9 +63,9 @@ func ProvideMessageHandler(
|
||||
messageService *service.MessageService,
|
||||
userService service.UserService,
|
||||
groupService service.GroupService,
|
||||
wsHub *ws.Hub,
|
||||
publisher ws.MessagePublisher,
|
||||
) *handler.MessageHandler {
|
||||
return handler.NewMessageHandler(chatService, messageService, userService, groupService, wsHub)
|
||||
return handler.NewMessageHandler(chatService, messageService, userService, groupService, publisher)
|
||||
}
|
||||
|
||||
// ProvideSystemMessageHandler 提供系统消息处理器
|
||||
@@ -93,14 +93,14 @@ func ProvideScheduleHandler(
|
||||
|
||||
// ProvideWSHandler 提供WebSocket处理器
|
||||
func ProvideWSHandler(
|
||||
wsHub *ws.Hub,
|
||||
publisher ws.MessagePublisher,
|
||||
chatService service.ChatService,
|
||||
groupService service.GroupService,
|
||||
jwtService *service.JWTService,
|
||||
callService service.CallService,
|
||||
userRepo repository.UserRepository,
|
||||
) *handler.WSHandler {
|
||||
return handler.NewWSHandler(wsHub, chatService, groupService, jwtService, callService, userRepo)
|
||||
return handler.NewWSHandler(publisher, chatService, groupService, jwtService, callService, userRepo)
|
||||
}
|
||||
|
||||
// ProvideAdminVerificationHandler 提供管理端身份认证处理器
|
||||
|
||||
Reference in New Issue
Block a user