You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
Open-IM-Server/internal/push/logic/init.go

70 lines
1.6 KiB

4 years ago
/*
** description("").
** copyright('open-im,www.open-im.io').
** author("fg,Gordon@open-im.io").
** time(2021/3/22 15:33).
*/
package logic
import (
3 years ago
pusher "Open_IM/internal/push"
fcm "Open_IM/internal/push/fcm"
3 years ago
"Open_IM/internal/push/getui"
jpush "Open_IM/internal/push/jpush"
2 years ago
"Open_IM/internal/push/mobpush"
"Open_IM/pkg/common/config"
"Open_IM/pkg/common/constant"
"Open_IM/pkg/common/kafka"
prome "Open_IM/pkg/common/prome"
3 years ago
"Open_IM/pkg/statistics"
"fmt"
4 years ago
)
var (
rpcServer RPCServer
pushCh PushConsumerHandler
producer *kafka.Producer
offlinePusher pusher.OfflinePusher
successCount uint64
4 years ago
)
func Init(rpcPort int) {
rpcServer.Init(rpcPort)
pushCh.Init()
4 years ago
}
func init() {
producer = kafka.NewKafkaProducer(config.Config.Kafka.Ws2mschat.Addr, config.Config.Kafka.Ws2mschat.Topic)
3 years ago
statistics.NewStatistics(&successCount, config.Config.ModuleName.PushName, fmt.Sprintf("%d second push to msg_gateway count", constant.StatisticsTimeInterval), constant.StatisticsTimeInterval)
2 years ago
if *config.Config.Push.Getui.Enable {
3 years ago
offlinePusher = getui.GetuiClient
}
if config.Config.Push.Jpns.Enable {
offlinePusher = jpush.JPushClient
}
if config.Config.Push.Fcm.Enable {
2 years ago
offlinePusher = fcm.NewFcm()
}
if config.Config.Push.Mob.Enable {
offlinePusher = mobpush.MobPushClient
}
4 years ago
}
func initPrometheus() {
2 years ago
prome.NewMsgOfflinePushSuccessCounter()
prome.NewMsgOfflinePushFailedCounter()
}
2 years ago
func Run(promethuesPort int) {
4 years ago
go rpcServer.run()
go pushCh.pushConsumerGroup.RegisterHandleAndConsumer(&pushCh)
2 years ago
go func() {
2 years ago
err := prome.StartPromeSrv(promethuesPort)
2 years ago
if err != nil {
panic(err)
}
}()
4 years ago
}