Merge branch 'tuoyun' of github.com:OpenIMSDK/Open-IM-Server into tuoyun

pull/218/head
wangchuxiao 3 years ago
commit 5c5e828cc6

@ -45,6 +45,7 @@ require (
github.com/spf13/viper v1.9.0
github.com/stretchr/testify v1.7.0
github.com/tencentyun/qcloud-cos-sts-sdk v0.0.0-20210325043845-84a0811633ca
github.com/tmc/grpc-websocket-proxy v0.0.0-20190109142713-0ad062ec5ee5 // indirect
go.etcd.io/etcd/api/v3 v3.5.2
go.etcd.io/etcd/client/v3 v3.5.2
go.mongodb.org/mongo-driver v1.8.3

@ -482,6 +482,7 @@ github.com/tidwall/pretty v1.0.0 h1:HsD+QiTn7sK6flMKIvNmpqz1qrpP3Ps6jOKIKMooyg4=
github.com/tidwall/pretty v1.0.0/go.mod h1:XNkn88O1ChpSDQmQeStsy+sBenx6DDtFZJxhVysOjyk=
github.com/tjfoc/gmsm v1.3.2 h1:7JVkAn5bvUJ7HtU08iW6UiD+UTmJTIToHCfeFzkcCxM=
github.com/tjfoc/gmsm v1.3.2/go.mod h1:HaUcFuY0auTiaHB9MHFGCPx5IaLhTUd2atbCFBQXn9w=
github.com/tmc/grpc-websocket-proxy v0.0.0-20190109142713-0ad062ec5ee5/go.mod h1:ncp9v5uamzpCO7NfCPTXjqaC+bZgJeR0sMTm6dMHP7U=
github.com/ugorji/go v1.1.7 h1:/68gy2h+1mWMrwZFeD1kQialdSzAb432dtpeJ42ovdo=
github.com/ugorji/go v1.1.7/go.mod h1:kZn38zHttfInRq0xu/PH0az30d+z6vm202qpg1oXVMw=
github.com/ugorji/go/codec v1.1.7 h1:2SvQaVZ1ouYrrKKwoSk2pzd4A9evlKJb9oTL+OaLUSs=

@ -1,6 +1,7 @@
package getcdv3
import (
"Open_IM/pkg/common/log"
"context"
"fmt"
"strings"
@ -43,6 +44,12 @@ func NewResolver(schema, etcdAddr, serviceName string) (*Resolver, error) {
r.schema = schema
r.etcdAddr = etcdAddr
resolver.Register(&r)
//
//ctx, _ := context.WithTimeout(context.Background(), time.Second*5)
//conn, err := grpc.DialContext(ctx, GetPrefix(schema, serviceName),
// grpc.WithDefaultServiceConfig(fmt.Sprintf(`{"LoadBalancingPolicy": "%s"}`, roundrobin.Name)),
// grpc.WithInsecure())
log.Debug("", "etcd key ", GetPrefix(schema, serviceName), "value ", *r.grpcClientConn)
conn, err := grpc.Dial(
GetPrefix(schema, serviceName),
@ -67,6 +74,7 @@ func GetConn(schema, etcdaddr, serviceName string) *grpc.ClientConn {
r, ok := nameResolver[schema+serviceName]
rwNameResolverMutex.RUnlock()
if ok {
log.Debug("", "etcd key ", schema+serviceName, "value ", *r.grpcClientConn, *r)
return r.grpcClientConn
}
@ -74,15 +82,18 @@ func GetConn(schema, etcdaddr, serviceName string) *grpc.ClientConn {
r, ok = nameResolver[schema+serviceName]
if ok {
rwNameResolverMutex.Unlock()
log.Debug("", "etcd key ", schema+serviceName, "value ", *r.grpcClientConn, *r)
return r.grpcClientConn
}
r, err := NewResolver(schema, etcdaddr, serviceName)
if err != nil {
log.Error("", "etcd failed ", schema, etcdaddr, serviceName)
rwNameResolverMutex.Unlock()
return nil
}
log.Debug("", "etcd key ", schema+serviceName, "value ", *r.grpcClientConn, *r)
nameResolver[schema+serviceName] = r
rwNameResolverMutex.Unlock()
return r.grpcClientConn

Loading…
Cancel
Save