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/init.go

60 lines
1.4 KiB

4 years ago
/*
** description("").
** copyright('open-im,www.open-im.io').
** author("fg,Gordon@open-im.io").
** time(2021/3/22 15:33).
*/
2 years ago
package push
4 years ago
import (
fcm "Open_IM/internal/push/fcm"
3 years ago
"Open_IM/internal/push/getui"
jpush "Open_IM/internal/push/jpush"
"Open_IM/pkg/common/config"
"Open_IM/pkg/common/constant"
2 years ago
"Open_IM/pkg/common/db/cache"
2 years ago
"Open_IM/pkg/common/prome"
3 years ago
"Open_IM/pkg/statistics"
"fmt"
4 years ago
)
2 years ago
type Push struct {
rpcServer RPCServer
2 years ago
pushCh ConsumerHandler
offlinePusher OfflinePusher
successCount uint64
2 years ago
}
4 years ago
2 years ago
func (p *Push) Init(rpcPort int) {
var cacheInterface cache.Cache
2 years ago
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)
2 years ago
if *config.Config.Push.Getui.Enable {
2 years ago
p.offlinePusher = getui.NewClient(cacheInterface)
3 years ago
}
if config.Config.Push.Jpns.Enable {
2 years ago
p.offlinePusher = jpush.NewClient()
3 years ago
}
if config.Config.Push.Fcm.Enable {
2 years ago
p.offlinePusher = fcm.NewClient(cacheInterface)
}
4 years ago
}
2 years ago
func (p *Push) initPrometheus() {
2 years ago
prome.NewMsgOfflinePushSuccessCounter()
prome.NewMsgOfflinePushFailedCounter()
}
2 years ago
func (p *Push) Run(prometheusPort int) {
go p.rpcServer.run()
go p.pushCh.pushConsumerGroup.RegisterHandleAndConsumer(&p.pushCh)
2 years ago
go func() {
2 years ago
err := prome.StartPromeSrv(prometheusPort)
2 years ago
if err != nil {
panic(err)
}
}()
4 years ago
}