xiaoluoluo commented on a change in pull request #1205:
URL:
https://github.com/apache/servicecomb-service-center/pull/1205#discussion_r780154763
##########
File path: client/set.go
##########
@@ -1,16 +1,25 @@
package client
import (
+ "errors"
"fmt"
v1sync "github.com/apache/servicecomb-service-center/api/sync/v1"
"github.com/apache/servicecomb-service-center/pkg/log"
"google.golang.org/grpc"
+ "google.golang.org/grpc/resolver"
+ "google.golang.org/grpc/resolver/manual"
+)
+
+var (
+ ErrAddrEmpty = errors.New("addr is empty")
+ ErrConnNil = errors.New("conn is nil")
)
// SetConfig is client configs
type SetConfig struct {
- Addr string
+ Addr []string
+ Scheme string
Review comment:
调用请求的时候 会 注册上 解析器 schema 是解析器的名字,这里可以根据自己的业务自己定义
##########
File path: client/set.go
##########
@@ -19,13 +28,35 @@ type Set struct {
}
// NewSetForConfig dial grpc connection and create all grpc clients
-func NewSetForConfig(c SetConfig) (*Set, error) {
- conn, err := grpc.Dial(c.Addr, grpc.WithInsecure())
+func NewSetForConfig(c SetConfig) (*grpc.ClientConn, *Set, error) {
+ if len(c.Addr) <= 0 {
+ return nil, nil, ErrAddrEmpty
+ }
+
+ var conn *grpc.ClientConn
+ var err error
+
+ if len(c.Addr) <= 1 {
+ conn, err = grpc.Dial(c.Addr[0], grpc.WithInsecure())
+ } else {
+ addr := make([]resolver.Address, 0, len(c.Addr))
+ for _, a := range c.Addr {
+ addr = append(addr, resolver.Address{Addr: a})
+ }
+ r := manual.NewBuilderWithScheme(c.Scheme)
+ r.InitialState(resolver.State{Addresses: addr})
+ conn, err = grpc.Dial(r.Scheme()+":///", grpc.WithInsecure(),
grpc.WithResolvers(r))
Review comment:
这里在请求的时候 grpc.WithResolvers(r)) 带上解析器
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]