proto modify

This commit is contained in:
wangchuxiao
2023-03-03 17:42:26 +08:00
parent 7050b64b19
commit 96d9b25b57
76 changed files with 1038 additions and 1230 deletions
-140
View File
@@ -107,143 +107,3 @@ func callbackBeforeSuperGroupOnlinePush(ctx context.Context, groupID string, msg
}
return nil
}
//func callbackOfflinePush(operationID string, userIDList []string, msg *common.MsgData, offlinePushUserIDList *[]string) cbApi.CommonCallbackResp {
// callbackResp := cbapi.CommonCallbackResp{OperationID: operationID}
// if !config.Config.Callback.CallbackOfflinePush.Enable {
// return callbackResp
// }
// req := cbApi.CallbackBeforePushReq{
// UserStatusBatchCallbackReq: cbApi.UserStatusBatchCallbackReq{
// UserStatusBaseCallback: cbApi.UserStatusBaseCallback{
// CallbackCommand: constant.CallbackOfflinePushCommand,
// OperationID: operationID,
// PlatformID: msg.SenderPlatformID,
// Platform: constant.PlatformIDToName(int(msg.SenderPlatformID)),
// },
// UserIDList: userIDList,
// },
// OfflinePushInfo: msg.OfflinePushInfo,
// ClientMsgID: msg.ClientMsgID,
// SendID: msg.SendID,
// GroupID: msg.GroupID,
// ContentType: msg.ContentType,
// SessionType: msg.SessionType,
// AtUserIDList: msg.AtUserIDList,
// Content: callback.GetContent(msg),
// }
// resp := &cbApi.CallbackBeforePushResp{CommonCallbackResp: &callbackResp}
// if err := http.CallBackPostReturn(config.Config.Callback.CallbackUrl, constant.CallbackOfflinePushCommand, req, resp, config.Config.Callback.CallbackOfflinePush.CallbackTimeOut); err != nil {
// callbackResp.ErrCode = http2.StatusInternalServerError
// callbackResp.ErrMsg = err.Error()
// if !*config.Config.Callback.CallbackOfflinePush.CallbackFailedContinue {
// callbackResp.ActionCode = constant.ActionForbidden
// return callbackResp
// } else {
// callbackResp.ActionCode = constant.ActionAllow
// return callbackResp
// }
// }
// if resp.ErrCode == constant.CallbackHandleSuccess && resp.ActionCode == constant.ActionAllow {
// if len(resp.UserIDList) != 0 {
// *offlinePushUserIDList = resp.UserIDList
// }
// if resp.OfflinePushInfo != nil {
// msg.OfflinePushInfo = resp.OfflinePushInfo
// }
// }
// log.NewDebug(operationID, utils.GetSelfFuncName(), offlinePushUserIDList, resp.UserIDList)
// return callbackResp
//}
//
//func callbackOnlinePush(operationID string, userIDList []string, msg *common.MsgData) cbApi.CommonCallbackResp {
// callbackResp := cbApi.CommonCallbackResp{OperationID: operationID}
// if !config.Config.Callback.CallbackOnlinePush.Enable || utils.IsContain(msg.SendID, userIDList) {
// return callbackResp
// }
// req := cbApi.CallbackBeforePushReq{
// UserStatusBatchCallbackReq: cbApi.UserStatusBatchCallbackReq{
// UserStatusBaseCallback: cbApi.UserStatusBaseCallback{
// CallbackCommand: constant.CallbackOnlinePushCommand,
// OperationID: operationID,
// PlatformID: msg.SenderPlatformID,
// Platform: constant.PlatformIDToName(int(msg.SenderPlatformID)),
// },
// UserIDList: userIDList,
// },
// //OfflinePushInfo: msg.OfflinePushInfo,
// ClientMsgID: msg.ClientMsgID,
// SendID: msg.SendID,
// GroupID: msg.GroupID,
// ContentType: msg.ContentType,
// SessionType: msg.SessionType,
// AtUserIDList: msg.AtUserIDList,
// Content: callback.GetContent(msg),
// }
// resp := &cbApi.CallbackBeforePushResp{CommonCallbackResp: &callbackResp}
// if err := http.CallBackPostReturn(config.Config.Callback.CallbackUrl, constant.CallbackOnlinePushCommand, req, resp, config.Config.Callback.CallbackOnlinePush.CallbackTimeOut); err != nil {
// callbackResp.ErrCode = http2.StatusInternalServerError
// callbackResp.ErrMsg = err.Error()
// if !config.Config.Callback.CallbackOnlinePush.CallbackFailedContinue {
// callbackResp.ActionCode = constant.ActionForbidden
// return callbackResp
// } else {
// callbackResp.ActionCode = constant.ActionAllow
// return callbackResp
// }
// }
// if resp.ErrCode == constant.CallbackHandleSuccess && resp.ActionCode == constant.ActionAllow {
// //if resp.OfflinePushInfo != nil {
// // msg.OfflinePushInfo = resp.OfflinePushInfo
// //}
// }
// return callbackResp
//}
//
//func callbackBeforeSuperGroupOnlinePush(operationID string, groupID string, msg *common.MsgData, pushToUserList *[]string) cbApi.CommonCallbackResp {
// log.Debug(operationID, utils.GetSelfFuncName(), groupID, msg.String(), pushToUserList)
// callbackResp := cbApi.CommonCallbackResp{OperationID: operationID}
// if !config.Config.Callback.CallbackBeforeSuperGroupOnlinePush.Enable {
// return callbackResp
// }
// req := cbApi.CallbackBeforeSuperGroupOnlinePushReq{
// UserStatusBaseCallback: cbApi.UserStatusBaseCallback{
// CallbackCommand: constant.CallbackSuperGroupOnlinePushCommand,
// OperationID: operationID,
// PlatformID: msg.SenderPlatformID,
// Platform: constant.PlatformIDToName(int(msg.SenderPlatformID)),
// },
// //OfflinePushInfo: msg.OfflinePushInfo,
// ClientMsgID: msg.ClientMsgID,
// SendID: msg.SendID,
// GroupID: groupID,
// ContentType: msg.ContentType,
// SessionType: msg.SessionType,
// AtUserIDList: msg.AtUserIDList,
// Content: callback.GetContent(msg),
// Seq: msg.Seq,
// }
// resp := &cbApi.CallbackBeforeSuperGroupOnlinePushResp{CommonCallbackResp: &callbackResp}
// if err := http.CallBackPostReturn(config.Config.Callback.CallbackUrl, constant.CallbackSuperGroupOnlinePushCommand, req, resp, config.Config.Callback.CallbackBeforeSuperGroupOnlinePush.CallbackTimeOut); err != nil {
// callbackResp.ErrCode = http2.StatusInternalServerError
// callbackResp.ErrMsg = err.Error()
// if !config.Config.Callback.CallbackBeforeSuperGroupOnlinePush.CallbackFailedContinue {
// callbackResp.ActionCode = constant.ActionForbidden
// return callbackResp
// } else {
// callbackResp.ActionCode = constant.ActionAllow
// return callbackResp
// }
// }
// if resp.ErrCode == constant.CallbackHandleSuccess && resp.ActionCode == constant.ActionAllow {
// if len(resp.UserIDList) != 0 {
// *pushToUserList = resp.UserIDList
// }
// //if resp.OfflinePushInfo != nil {
// // msg.OfflinePushInfo = resp.OfflinePushInfo
// //}
// }
// log.NewDebug(operationID, utils.GetSelfFuncName(), pushToUserList, resp.UserIDList)
// return callbackResp
//
//}
+36
View File
@@ -0,0 +1,36 @@
/*
** description("").
** copyright('open-im,www.open-im.io').
** author("fg,Gordon@open-im.io").
** time(2021/3/22 15:33).
*/
package push
import (
"OpenIM/pkg/common/config"
"OpenIM/pkg/common/constant"
"OpenIM/pkg/common/prome"
"OpenIM/pkg/statistics"
"fmt"
)
type Consumer struct {
pushCh ConsumerHandler
successCount uint64
}
func NewConsumer(pusher *Pusher) *Consumer {
return &Consumer{
pushCh: *NewConsumerHandler(pusher),
}
}
func (c *Consumer) initPrometheus() {
prome.NewMsgOfflinePushSuccessCounter()
prome.NewMsgOfflinePushFailedCounter()
}
func (c *Consumer) Start() {
statistics.NewStatistics(&c.successCount, config.Config.ModuleName.PushName, fmt.Sprintf("%d second push to msg_gateway count", constant.StatisticsTimeInterval), constant.StatisticsTimeInterval)
go c.pushCh.pushConsumerGroup.RegisterHandleAndConsumer(&c.pushCh)
}
+2 -2
View File
@@ -19,10 +19,10 @@ var Terminal = []int{constant.IOSPlatformID, constant.AndroidPlatformID, constan
type Fcm struct {
fcmMsgCli *messaging.Client
cache cache.Cache
cache cache.Model
}
func NewClient(cache cache.Cache) *Fcm {
func NewClient(cache cache.Model) *Fcm {
opt := option.WithCredentialsFile(filepath.Join(config.Root, "config", config.Config.Push.Fcm.ServiceAccount))
fcmApp, err := firebase.NewApp(context.Background(), nil, opt)
if err != nil {
+1 -1
View File
@@ -9,7 +9,7 @@ import (
)
func Test_Push(t *testing.T) {
var redis cache.Cache
var redis cache.Model
offlinePusher := NewClient(redis)
err := offlinePusher.Push(context.Background(), []string{"userID1"}, "test", "test", &push.Opts{})
assert.Nil(t, err)
+2 -2
View File
@@ -38,12 +38,12 @@ const (
)
type Client struct {
cache cache.Cache
cache cache.Model
tokenExpireTime int64
taskIDTTL int64
}
func NewClient(cache cache.Cache) *Client {
func NewClient(cache cache.Model) *Client {
return &Client{cache: cache, tokenExpireTime: tokenExpireTime, taskIDTTL: taskIDTTL}
}
-63
View File
@@ -1,63 +0,0 @@
/*
** description("").
** copyright('open-im,www.open-im.io').
** author("fg,Gordon@open-im.io").
** time(2021/3/22 15:33).
*/
package push
import (
fcm "OpenIM/internal/push/fcm"
"OpenIM/internal/push/getui"
jpush "OpenIM/internal/push/jpush"
"OpenIM/pkg/common/config"
"OpenIM/pkg/common/constant"
"OpenIM/pkg/common/db/cache"
"OpenIM/pkg/common/prome"
"OpenIM/pkg/statistics"
"fmt"
)
type Push struct {
rpcServer PushServer
pushCh ConsumerHandler
offlinePusher OfflinePusher
successCount uint64
}
func (p *Push) Init(rpcPort int) error {
rdb, err := cache.NewRedis()
if err != nil {
return err
}
var cacheInterface cache.Cache
p.rpcServer.Init(rpcPort, cacheInterface)
p.pushCh.Init()
statistics.NewStatistics(&p.successCount, config.Config.ModuleName.PushName, fmt.Sprintf("%d second push to msg_gateway count", constant.StatisticsTimeInterval), constant.StatisticsTimeInterval)
if *config.Config.Push.Getui.Enable {
p.offlinePusher = getui.NewClient(cacheInterface)
}
if config.Config.Push.Jpns.Enable {
p.offlinePusher = jpush.NewClient()
}
if config.Config.Push.Fcm.Enable {
p.offlinePusher = fcm.NewClient(cacheInterface)
}
return nil
}
func (p *Push) initPrometheus() {
prome.NewMsgOfflinePushSuccessCounter()
prome.NewMsgOfflinePushFailedCounter()
}
func (p *Push) Run(prometheusPort int) {
go p.rpcServer.run()
go p.pushCh.pushConsumerGroup.RegisterHandleAndConsumer(&p.pushCh)
go func() {
err := prome.StartPrometheusSrv(prometheusPort)
if err != nil {
panic(err)
}
}()
}
+1 -1
View File
@@ -1,4 +1,4 @@
package push
package jpush
import (
"OpenIM/internal/push"
+39
View File
@@ -0,0 +1,39 @@
package push
import (
"OpenIM/internal/push/fcm"
"OpenIM/internal/push/getui"
"OpenIM/internal/push/jpush"
"OpenIM/pkg/common/config"
"OpenIM/pkg/common/db/cache"
"context"
)
type OfflinePusher interface {
Push(ctx context.Context, userIDs []string, title, content string, opts *Opts) error
}
func NewOfflinePusher(cache cache.Model) OfflinePusher {
var offlinePusher OfflinePusher
if config.Config.Push.Getui.Enable {
offlinePusher = getui.NewClient(cache)
}
if config.Config.Push.Fcm.Enable {
offlinePusher = fcm.NewClient(cache)
}
if config.Config.Push.Jpns.Enable {
offlinePusher = jpush.NewClient()
}
return offlinePusher
}
type Opts struct {
Signal *Signal
IOSPushSound string
IOSBadgeCount bool
Ex string
}
type Signal struct {
ClientMsgID string
}
+10 -7
View File
@@ -22,16 +22,19 @@ import (
type ConsumerHandler struct {
pushConsumerGroup *kfk.MConsumerGroup
pusher Pusher
pusher *Pusher
}
func (c *ConsumerHandler) Init() {
c.pushConsumerGroup = kfk.NewMConsumerGroup(&kfk.MConsumerGroupConfig{KafkaVersion: sarama.V2_0_0_0,
func NewConsumerHandler(pusher *Pusher) *ConsumerHandler {
var consumerHandler ConsumerHandler
consumerHandler.pusher = pusher
consumerHandler.pushConsumerGroup = kfk.NewMConsumerGroup(&kfk.MConsumerGroupConfig{KafkaVersion: sarama.V2_0_0_0,
OffsetsInitial: sarama.OffsetNewest, IsReturnErr: false}, []string{config.Config.Kafka.Ms2pschat.Topic}, config.Config.Kafka.Ms2pschat.Addr,
config.Config.Kafka.ConsumerGroupID.MsgToPush)
return &consumerHandler
}
func (c *ConsumerHandler) handleMs2PsChat(msg []byte) {
func (c *ConsumerHandler) handleMs2PsChat(ctx context.Context, msg []byte) {
log.NewDebug("", "msg come from kafka And push!!!", "msg", string(msg))
msgFromMQ := pbChat.PushMsgDataToMQ{}
if err := proto.Unmarshal(msg, &msgFromMQ); err != nil {
@@ -40,14 +43,13 @@ func (c *ConsumerHandler) handleMs2PsChat(msg []byte) {
}
pbData := &pbPush.PushMsgReq{
MsgData: msgFromMQ.MsgData,
SourceID: msgFromMQ.PushToUserID,
SourceID: msgFromMQ.SourceID,
}
sec := msgFromMQ.MsgData.SendTime / 1000
nowSec := utils.GetCurrentTimestampBySecond()
if nowSec-sec > 10 {
return
}
ctx := context.Background()
tracelog.SetOperationID(ctx, "")
var err error
switch msgFromMQ.MsgData.SessionType {
@@ -66,7 +68,8 @@ func (c *ConsumerHandler) ConsumeClaim(sess sarama.ConsumerGroupSession,
claim sarama.ConsumerGroupClaim) error {
for msg := range claim.Messages() {
log.NewDebug("", "kafka get info to mysql", "msgTopic", msg.Topic, "msgPartition", msg.Partition, "msg", string(msg.Value))
c.handleMs2PsChat(msg.Value)
ctx := c.pushConsumerGroup.GetContextFromMsg(msg)
c.handleMs2PsChat(ctx, msg.Value)
sess.MarkMessage(msg, "")
}
return nil
-18
View File
@@ -1,18 +0,0 @@
package push
import "context"
type OfflinePusher interface {
Push(ctx context.Context, userIDs []string, title, content string, opts *Opts) error
}
type Opts struct {
Signal *Signal
IOSPushSound string
IOSBadgeCount bool
Ex string
}
type Signal struct {
ClientMsgID string
}
+29 -6
View File
@@ -1,24 +1,47 @@
package push
import (
"OpenIM/pkg/common/config"
"OpenIM/pkg/common/constant"
"OpenIM/pkg/common/db/cache"
"OpenIM/pkg/common/db/controller"
"OpenIM/pkg/common/db/localcache"
"OpenIM/pkg/discoveryregistry"
pbPush "OpenIM/pkg/proto/push"
"context"
"github.com/OpenIMSDK/openKeeper"
"google.golang.org/grpc"
"sync"
)
type pushServer struct {
pusher *Pusher
}
func Start(client *openKeeper.ZkClient, server *grpc.Server) error {
func Start(client discoveryregistry.SvcDiscoveryRegistry, server *grpc.Server) error {
rdb, err := cache.NewRedis()
if err != nil {
return err
}
cacheModel := cache.NewCacheModel(rdb)
pbPush.RegisterPushMsgServiceServer(server, &pushServer{
pusher: NewPusher(),
})
offlinePusher := NewOfflinePusher(cacheModel)
database := controller.NewPushDatabase(cacheModel)
pusher := NewPusher(client, offlinePusher, database, localcache.NewGroupLocalCache(client), localcache.NewConversationLocalCache(client))
var wg sync.WaitGroup
wg.Add(2)
go func() {
defer wg.Done()
pbPush.RegisterPushMsgServiceServer(server, &pushServer{
pusher: pusher,
})
}()
go func() {
defer wg.Done()
consumer := NewConsumer(pusher)
consumer.initPrometheus()
consumer.Start()
}()
wg.Wait()
return nil
}
func (r *pushServer) PushMsg(ctx context.Context, pbData *pbPush.PushMsgReq) (resp *pbPush.PushMsgResp, err error) {
+5 -5
View File
@@ -27,13 +27,13 @@ type Pusher struct {
database controller.PushDatabase
client discoveryregistry.SvcDiscoveryRegistry
offlinePusher OfflinePusher
groupLocalCache localcache.GroupLocalCache
conversationLocalCache localcache.ConversationLocalCache
groupLocalCache *localcache.GroupLocalCache
conversationLocalCache *localcache.ConversationLocalCache
successCount int
}
func NewPusher(client discoveryregistry.SvcDiscoveryRegistry, offlinePusher OfflinePusher, database controller.PushDatabase,
groupLocalCache localcache.GroupLocalCache, conversationLocalCache localcache.ConversationLocalCache) *Pusher {
groupLocalCache *localcache.GroupLocalCache, conversationLocalCache *localcache.ConversationLocalCache) *Pusher {
return &Pusher{
database: database,
client: client,
@@ -162,7 +162,7 @@ func (p *Pusher) MsgToSuperGroupUser(ctx context.Context, groupID string, msg *s
return nil
}
func (p *Pusher) GetConnsAndOnlinePush(ctx context.Context, msg *sdkws.MsgData, pushToUserIDs []string) (wsResults []*msggateway.SingleMsgToUserResultList, err error) {
func (p *Pusher) GetConnsAndOnlinePush(ctx context.Context, msg *sdkws.MsgData, pushToUserIDs []string) (wsResults []*msggateway.SingleMsgToUserResults, err error) {
conns, err := p.client.GetConns(config.Config.RpcRegisterName.OpenImMessageGatewayName)
if err != nil {
return nil, err
@@ -170,7 +170,7 @@ func (p *Pusher) GetConnsAndOnlinePush(ctx context.Context, msg *sdkws.MsgData,
//Online push message
for _, v := range conns {
msgClient := msggateway.NewMsgGatewayClient(v)
reply, err := msgClient.SuperGroupOnlineBatchPushOneMsg(ctx, &msggateway.OnlineBatchPushOneMsgReq{OperationID: tracelog.GetOperationID(ctx), MsgData: msg, PushToUserIDList: pushToUserIDs})
reply, err := msgClient.SuperGroupOnlineBatchPushOneMsg(ctx, &msggateway.OnlineBatchPushOneMsgReq{MsgData: msg, PushToUserIDs: pushToUserIDs})
if err != nil {
log.NewError(tracelog.GetOperationID(ctx), msg, len(pushToUserIDs), "err", err)
continue