|
|
|
@ -30,18 +30,21 @@ import (
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
type (
|
|
|
|
|
// MessageInterceptorChain defines a chain of message interceptor functions.
|
|
|
|
|
MessageInterceptorChain []MessageInterceptorFunc
|
|
|
|
|
msgServer struct {
|
|
|
|
|
RegisterCenter discoveryregistry.SvcDiscoveryRegistry
|
|
|
|
|
MsgDatabase controller.CommonMsgDatabase
|
|
|
|
|
Conversation *rpcclient.ConversationRpcClient
|
|
|
|
|
UserLocalCache *rpccache.UserLocalCache
|
|
|
|
|
FriendLocalCache *rpccache.FriendLocalCache
|
|
|
|
|
GroupLocalCache *rpccache.GroupLocalCache
|
|
|
|
|
ConversationLocalCache *rpccache.ConversationLocalCache
|
|
|
|
|
Handlers MessageInterceptorChain
|
|
|
|
|
notificationSender *rpcclient.NotificationSender
|
|
|
|
|
config *config.GlobalConfig
|
|
|
|
|
|
|
|
|
|
// msgServer encapsulates dependencies required for message handling.
|
|
|
|
|
msgServer struct {
|
|
|
|
|
RegisterCenter discoveryregistry.SvcDiscoveryRegistry // Service discovery registry for service registration.
|
|
|
|
|
MsgDatabase controller.CommonMsgDatabase // Interface for message database operations.
|
|
|
|
|
Conversation *rpcclient.ConversationRpcClient // RPC client for conversation service.
|
|
|
|
|
UserLocalCache *rpccache.UserLocalCache // Local cache for user data.
|
|
|
|
|
FriendLocalCache *rpccache.FriendLocalCache // Local cache for friend data.
|
|
|
|
|
GroupLocalCache *rpccache.GroupLocalCache // Local cache for group data.
|
|
|
|
|
ConversationLocalCache *rpccache.ConversationLocalCache // Local cache for conversation data.
|
|
|
|
|
Handlers MessageInterceptorChain // Chain of handlers for processing messages.
|
|
|
|
|
notificationSender *rpcclient.NotificationSender // RPC client for sending notifications.
|
|
|
|
|
config *config.GlobalConfig // Global configuration settings.
|
|
|
|
|
}
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
@ -61,24 +64,24 @@ func (m *msgServer) addInterceptorHandler(interceptorFunc ...MessageInterceptorF
|
|
|
|
|
//}
|
|
|
|
|
|
|
|
|
|
func Start(config *config.GlobalConfig, client discoveryregistry.SvcDiscoveryRegistry, server *grpc.Server) error {
|
|
|
|
|
rdb, err := cache.NewRedis(config)
|
|
|
|
|
rdb, err := cache.NewRedis(&config.Redis)
|
|
|
|
|
if err != nil {
|
|
|
|
|
return err
|
|
|
|
|
}
|
|
|
|
|
mongo, err := unrelation.NewMongo(config)
|
|
|
|
|
mongo, err := unrelation.NewMongo(&config.Mongo)
|
|
|
|
|
if err != nil {
|
|
|
|
|
return err
|
|
|
|
|
}
|
|
|
|
|
if err := mongo.CreateMsgIndex(); err != nil {
|
|
|
|
|
return err
|
|
|
|
|
}
|
|
|
|
|
cacheModel := cache.NewMsgCacheModel(rdb, config)
|
|
|
|
|
cacheModel := cache.NewMsgCacheModel(rdb, config.MsgCacheTimeout, &config.Redis)
|
|
|
|
|
msgDocModel := unrelation.NewMsgMongoDriver(mongo.GetDatabase(config.Mongo.Database))
|
|
|
|
|
conversationClient := rpcclient.NewConversationRpcClient(client, config)
|
|
|
|
|
conversationClient := rpcclient.NewConversationRpcClient(client, config.RpcRegisterName.OpenImConversationName)
|
|
|
|
|
userRpcClient := rpcclient.NewUserRpcClient(client, config.RpcRegisterName.OpenImUserName, &config.Manager, &config.IMAdmin)
|
|
|
|
|
groupRpcClient := rpcclient.NewGroupRpcClient(client, config)
|
|
|
|
|
friendRpcClient := rpcclient.NewFriendRpcClient(client, config)
|
|
|
|
|
msgDatabase, err := controller.NewCommonMsgDatabase(msgDocModel, cacheModel, config)
|
|
|
|
|
groupRpcClient := rpcclient.NewGroupRpcClient(client, config.RpcRegisterName.OpenImGroupName)
|
|
|
|
|
friendRpcClient := rpcclient.NewFriendRpcClient(client, config.RpcRegisterName.OpenImFriendName)
|
|
|
|
|
msgDatabase, err := controller.NewCommonMsgDatabase(msgDocModel, cacheModel, &config.Kafka)
|
|
|
|
|
if err != nil {
|
|
|
|
|
return err
|
|
|
|
|
}
|
|
|
|
@ -92,7 +95,8 @@ func Start(config *config.GlobalConfig, client discoveryregistry.SvcDiscoveryReg
|
|
|
|
|
FriendLocalCache: rpccache.NewFriendLocalCache(friendRpcClient, rdb),
|
|
|
|
|
config: config,
|
|
|
|
|
}
|
|
|
|
|
s.notificationSender = rpcclient.NewNotificationSender(config, rpcclient.WithLocalSendMsg(s.SendMsg))
|
|
|
|
|
|
|
|
|
|
s.notificationSender = rpcclient.NewNotificationSender(&config.Notification, rpcclient.WithLocalSendMsg(s.SendMsg))
|
|
|
|
|
s.addInterceptorHandler(MessageHasReadEnabled)
|
|
|
|
|
msg.RegisterMsgServer(server, s)
|
|
|
|
|
return nil
|
|
|
|
|