|
|
|
@ -13,10 +13,11 @@ import (
|
|
|
|
|
"github.com/OpenIMSDK/openKeeper"
|
|
|
|
|
grpcPrometheus "github.com/grpc-ecosystem/go-grpc-prometheus"
|
|
|
|
|
"google.golang.org/grpc"
|
|
|
|
|
"google.golang.org/grpc/credentials/insecure"
|
|
|
|
|
"net"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
func start(rpcPort int, rpcRegisterName string, prometheusPort int, rpcFn func(client discoveryregistry.SvcDiscoveryRegistry, server *grpc.Server) error, options []grpc.ServerOption) error {
|
|
|
|
|
func Start(rpcPort int, rpcRegisterName string, prometheusPort int, rpcFn func(client discoveryregistry.SvcDiscoveryRegistry, server *grpc.Server) error, options ...grpc.ServerOption) error {
|
|
|
|
|
fmt.Println("start", rpcRegisterName, "rpc server, port: ", rpcPort, "prometheusPort:", prometheusPort, ", OpenIM version: ", config.Version)
|
|
|
|
|
log.NewPrivateLog(constant.LogFileName)
|
|
|
|
|
listener, err := net.Listen("tcp", fmt.Sprintf("%s:%d", config.Config.ListenIP, rpcPort))
|
|
|
|
@ -47,19 +48,24 @@ func start(rpcPort int, rpcRegisterName string, prometheusPort int, rpcFn func(c
|
|
|
|
|
}
|
|
|
|
|
srv := grpc.NewServer(options...)
|
|
|
|
|
defer srv.GracefulStop()
|
|
|
|
|
err = zkClient.Register(rpcRegisterName, registerIP, rpcPort)
|
|
|
|
|
err = zkClient.Register(rpcRegisterName, registerIP, rpcPort, grpc.WithTransportCredentials(insecure.NewCredentials()))
|
|
|
|
|
if err != nil {
|
|
|
|
|
return utils.Wrap1(err)
|
|
|
|
|
}
|
|
|
|
|
go func() {
|
|
|
|
|
if config.Config.Prometheus.Enable && prometheusPort != 0 {
|
|
|
|
|
err := prome.StartPrometheusSrv(prometheusPort)
|
|
|
|
|
if err != nil {
|
|
|
|
|
return err
|
|
|
|
|
if err := prome.StartPrometheusSrv(prometheusPort); err != nil {
|
|
|
|
|
panic(err.Error())
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}()
|
|
|
|
|
err = srv.Serve(listener)
|
|
|
|
|
if err != nil {
|
|
|
|
|
return utils.Wrap1(err)
|
|
|
|
|
}
|
|
|
|
|
return rpcFn(zkClient, srv)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func Start(rpcPort int, rpcRegisterName string, prometheusPort int, rpcFn func(client discoveryregistry.SvcDiscoveryRegistry, server *grpc.Server) error, options ...grpc.ServerOption) error {
|
|
|
|
|
return start(rpcPort, rpcRegisterName, prometheusPort, rpcFn, options)
|
|
|
|
|
}
|
|
|
|
|
//func Start(rpcPort int, rpcRegisterName string, prometheusPort int, rpcFn func(client discoveryregistry.SvcDiscoveryRegistry, server *grpc.Server) error, options ...grpc.ServerOption) error {
|
|
|
|
|
// return start(rpcPort, rpcRegisterName, prometheusPort, rpcFn, options)
|
|
|
|
|
//}
|
|
|
|
|