Files
open-im-server/internal/push/logic/init.go
T

70 lines
1.6 KiB
Go
Raw Normal View History

2021-05-26 19:22:11 +08:00
/*
** description("").
** copyright('open-im,www.open-im.io').
** author("fg,Gordon@open-im.io").
** time(2021/3/22 15:33).
*/
package logic
import (
2022-05-25 15:48:48 +08:00
pusher "Open_IM/internal/push"
fcm "Open_IM/internal/push/fcm"
2022-05-25 15:48:48 +08:00
"Open_IM/internal/push/getui"
jpush "Open_IM/internal/push/jpush"
2022-09-29 15:23:28 +08:00
"Open_IM/internal/push/mobpush"
"Open_IM/pkg/common/config"
2021-11-25 14:12:52 +08:00
"Open_IM/pkg/common/constant"
"Open_IM/pkg/common/kafka"
2022-09-12 19:32:24 +08:00
promePkg "Open_IM/pkg/common/prometheus"
2022-02-25 19:49:38 +08:00
"Open_IM/pkg/statistics"
"fmt"
2021-05-26 19:22:11 +08:00
)
var (
2022-08-30 22:04:13 +08:00
rpcServer RPCServer
pushCh PushConsumerHandler
producer *kafka.Producer
offlinePusher pusher.OfflinePusher
successCount uint64
2021-05-26 19:22:11 +08:00
)
func Init(rpcPort int) {
rpcServer.Init(rpcPort)
pushCh.Init()
2022-08-30 22:04:13 +08:00
2021-05-26 19:22:11 +08:00
}
func init() {
producer = kafka.NewKafkaProducer(config.Config.Kafka.Ws2mschat.Addr, config.Config.Kafka.Ws2mschat.Topic)
2022-05-09 18:23:06 +08:00
statistics.NewStatistics(&successCount, config.Config.ModuleName.PushName, fmt.Sprintf("%d second push to msg_gateway count", constant.StatisticsTimeInterval), constant.StatisticsTimeInterval)
2022-11-10 14:51:35 +08:00
if *config.Config.Push.Getui.Enable {
2022-05-25 15:48:48 +08:00
offlinePusher = getui.GetuiClient
}
if config.Config.Push.Jpns.Enable {
offlinePusher = jpush.JPushClient
}
if config.Config.Push.Fcm.Enable {
2022-07-28 18:58:57 +08:00
offlinePusher = fcm.NewFcm()
}
2022-09-23 17:40:48 +08:00
if config.Config.Push.Mob.Enable {
offlinePusher = mobpush.MobPushClient
}
2021-05-26 19:22:11 +08:00
}
2022-09-15 12:07:28 +08:00
func initPrometheus() {
promePkg.NewMsgOfflinePushSuccessCounter()
promePkg.NewMsgOfflinePushFailedCounter()
}
2022-09-12 19:32:24 +08:00
func Run(promethuesPort int) {
2021-05-26 19:22:11 +08:00
go rpcServer.run()
go pushCh.pushConsumerGroup.RegisterHandleAndConsumer(&pushCh)
2022-09-12 19:32:24 +08:00
go func() {
err := promePkg.StartPromeSrv(promethuesPort)
if err != nil {
panic(err)
}
}()
2021-05-26 19:22:11 +08:00
}