pull/455/head
wenxu12345 3 years ago committed by Xinwei Xiong(cubxxw-openim)
parent 41d94e2f40
commit e1ee0500ea

@ -1,6 +1,7 @@
package getcdv3
import (
"Open_IM/pkg/common/log"
"context"
"fmt"
"strings"
@ -48,6 +49,8 @@ func NewResolver(schema, etcdAddr, serviceName string) (*Resolver, error) {
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),
// grpc.WithDefaultServiceConfig(fmt.Sprintf(`{"LoadBalancingPolicy": "%s"}`, roundrobin.Name)),
@ -71,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
}
@ -78,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