Skip to content

Commit

Permalink
feat: make listening only after connection to components prepared (#214)
Browse files Browse the repository at this point in the history
* feat: make listening only when connection to components prepared

* feat: use utils.Wrap1 to srround ret err
  • Loading branch information
CNCSMonster authored Sep 20, 2023
1 parent f17c398 commit 99834ac
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions pkg/common/chatrpcstart/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,7 @@ import (

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, "server, port: ", rpcPort, "prometheusPort:", prometheusPort, ", OpenIM version: ", config.Version)
listener, err := net.Listen("tcp", net.JoinHostPort(network.GetListenIP(config.Config.Rpc.ListenIP), strconv.Itoa(rpcPort)))
if err != nil {
return err
}
defer listener.Close()

zkClient, err := openKeeper.NewClient(config.Config.Zookeeper.ZkAddr, config.Config.Zookeeper.Schema,
openKeeper.WithFreq(time.Hour), openKeeper.WithUserNameAndPassword(config.Config.Zookeeper.Username,
config.Config.Zookeeper.Password), openKeeper.WithRoundRobin(), openKeeper.WithTimeout(10), openKeeper.WithLogger(log.NewZkLogger()))
Expand All @@ -50,7 +46,7 @@ func Start(rpcPort int, rpcRegisterName string, prometheusPort int, rpcFn func(c
zkClient.AddOption(chatMw.AddUserType(), mw.GrpcClient(), grpc.WithTransportCredentials(insecure.NewCredentials()))
registerIP, err := network.GetRpcRegisterIP(config.Config.Rpc.RegisterIP)
if err != nil {
return err
return utils.Wrap1(err)
}
srv := grpc.NewServer(append(options, mw.GrpcServer())...)
defer srv.GracefulStop()
Expand All @@ -62,5 +58,10 @@ func Start(rpcPort int, rpcRegisterName string, prometheusPort int, rpcFn func(c
if err != nil {
return utils.Wrap1(err)
}
listener, err := net.Listen("tcp", net.JoinHostPort(network.GetListenIP(config.Config.Rpc.ListenIP), strconv.Itoa(rpcPort)))
if err != nil {
return utils.Wrap1(err)
}
defer listener.Close()
return utils.Wrap1(srv.Serve(listener))
}

0 comments on commit 99834ac

Please sign in to comment.