|
|
@ -45,18 +45,18 @@ func NewResolver(schema, etcdAddr, serviceName string) (*Resolver, error) {
|
|
|
|
r.etcdAddr = etcdAddr
|
|
|
|
r.etcdAddr = etcdAddr
|
|
|
|
resolver.Register(&r)
|
|
|
|
resolver.Register(&r)
|
|
|
|
//
|
|
|
|
//
|
|
|
|
//ctx, _ := context.WithTimeout(context.Background(), time.Second*5)
|
|
|
|
ctx, _ := context.WithTimeout(context.Background(), time.Second*5)
|
|
|
|
//conn, err := grpc.DialContext(ctx, GetPrefix(schema, serviceName),
|
|
|
|
conn, err := grpc.DialContext(ctx, GetPrefix(schema, serviceName),
|
|
|
|
// grpc.WithDefaultServiceConfig(fmt.Sprintf(`{"LoadBalancingPolicy": "%s"}`, roundrobin.Name)),
|
|
|
|
grpc.WithDefaultServiceConfig(fmt.Sprintf(`{"LoadBalancingPolicy": "%s"}`, roundrobin.Name)),
|
|
|
|
// grpc.WithInsecure())
|
|
|
|
grpc.WithInsecure())
|
|
|
|
log.Debug("", "etcd key ", GetPrefix(schema, serviceName))
|
|
|
|
log.Debug("", "etcd key ", GetPrefix(schema, serviceName))
|
|
|
|
|
|
|
|
|
|
|
|
conn, err := grpc.Dial(
|
|
|
|
//conn, err := grpc.Dial(
|
|
|
|
GetPrefix(schema, serviceName),
|
|
|
|
// GetPrefix(schema, serviceName),
|
|
|
|
grpc.WithDefaultServiceConfig(fmt.Sprintf(`{"LoadBalancingPolicy": "%s"}`, roundrobin.Name)),
|
|
|
|
// grpc.WithDefaultServiceConfig(fmt.Sprintf(`{"LoadBalancingPolicy": "%s"}`, roundrobin.Name)),
|
|
|
|
grpc.WithInsecure(),
|
|
|
|
// grpc.WithInsecure(),
|
|
|
|
grpc.WithTimeout(time.Duration(5)*time.Second),
|
|
|
|
// grpc.WithTimeout(time.Duration(5)*time.Second),
|
|
|
|
)
|
|
|
|
//)
|
|
|
|
if err == nil {
|
|
|
|
if err == nil {
|
|
|
|
r.grpcClientConn = conn
|
|
|
|
r.grpcClientConn = conn
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -104,7 +104,7 @@ func (r *Resolver) Build(target resolver.Target, cc resolver.ClientConn, opts re
|
|
|
|
return nil, fmt.Errorf("etcd clientv3 client failed, etcd:%s", target)
|
|
|
|
return nil, fmt.Errorf("etcd clientv3 client failed, etcd:%s", target)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
r.cc = cc
|
|
|
|
r.cc = cc
|
|
|
|
|
|
|
|
log.Debug("", "Build..")
|
|
|
|
ctx, _ := context.WithTimeout(context.Background(), 5*time.Second)
|
|
|
|
ctx, _ := context.WithTimeout(context.Background(), 5*time.Second)
|
|
|
|
// "%s:///%s"
|
|
|
|
// "%s:///%s"
|
|
|
|
prefix := GetPrefix(r.schema, r.serviceName)
|
|
|
|
prefix := GetPrefix(r.schema, r.serviceName)
|
|
|
|