From 5148f3fdb6d6b8bf30cb81b57987faf160c68107 Mon Sep 17 00:00:00 2001 From: wangchuxiao Date: Wed, 17 Aug 2022 12:58:51 +0800 Subject: [PATCH] etcd --- pkg/grpc-etcdv3/getcdv3/resolver.go | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/pkg/grpc-etcdv3/getcdv3/resolver.go b/pkg/grpc-etcdv3/getcdv3/resolver.go index 76fe1d75f..1c408e197 100644 --- a/pkg/grpc-etcdv3/getcdv3/resolver.go +++ b/pkg/grpc-etcdv3/getcdv3/resolver.go @@ -194,7 +194,30 @@ func (r *Resolver) watch(prefix string, addrList []resolver.Address) { } } -func GetConn4Unique(schema, etcdaddr, servicename string) []*grpc.ClientConn { +func GetDefaultConn4Unique(schema, etcdaddr, servicename, operationID string) []*grpc.ClientConn { + grpcConns := getConn4Unique(schema, etcdaddr, servicename) + if len(grpcConns) > 0 { + return grpcConns + } + log.NewWarn(operationID, utils.GetSelfFuncName(), " len(grpcConns) < 0 ", schema, etcdaddr, servicename) + grpcConns = getConn4UniqueFromConfig(servicename, operationID) + return grpcConns +} + +func getConn4UniqueFromConfig(servicename, operationID string) []*grpc.ClientConn { + rpcRegisterIP := config.Config.RpcRegisterIP + var err error + if config.Config.RpcRegisterIP == "" { + rpcRegisterIP, err = utils.GetLocalIP() + if err != nil { + log.Error("", "GetLocalIP failed ", err.Error()) + return nil + } + } + return nil +} + +func getConn4Unique(schema, etcdaddr, servicename string) []*grpc.ClientConn { gEtcdCli, err := clientv3.New(clientv3.Config{Endpoints: strings.Split(etcdaddr, ",")}) if err != nil { log.Error("clientv3.New failed", err.Error())