|
|
@ -34,9 +34,11 @@ var _grpcTarget flagvar.StringVars |
|
|
|
var ( |
|
|
|
var ( |
|
|
|
_once sync.Once |
|
|
|
_once sync.Once |
|
|
|
_defaultCliConf = &ClientConfig{ |
|
|
|
_defaultCliConf = &ClientConfig{ |
|
|
|
Dial: xtime.Duration(time.Second * 10), |
|
|
|
Dial: xtime.Duration(time.Second * 10), |
|
|
|
Timeout: xtime.Duration(time.Millisecond * 250), |
|
|
|
Timeout: xtime.Duration(time.Millisecond * 250), |
|
|
|
Subset: 50, |
|
|
|
Subset: 50, |
|
|
|
|
|
|
|
KeepAliveInterval: xtime.Duration(time.Second * 60), |
|
|
|
|
|
|
|
KeepAliveTimeout: xtime.Duration(time.Second * 20), |
|
|
|
} |
|
|
|
} |
|
|
|
_defaultClient *Client |
|
|
|
_defaultClient *Client |
|
|
|
) |
|
|
|
) |
|
|
@ -51,14 +53,17 @@ func baseMetadata() metadata.MD { |
|
|
|
|
|
|
|
|
|
|
|
// ClientConfig is rpc client conf.
|
|
|
|
// ClientConfig is rpc client conf.
|
|
|
|
type ClientConfig struct { |
|
|
|
type ClientConfig struct { |
|
|
|
Dial xtime.Duration |
|
|
|
Dial xtime.Duration |
|
|
|
Timeout xtime.Duration |
|
|
|
Timeout xtime.Duration |
|
|
|
Breaker *breaker.Config |
|
|
|
Breaker *breaker.Config |
|
|
|
Method map[string]*ClientConfig |
|
|
|
Method map[string]*ClientConfig |
|
|
|
Clusters []string |
|
|
|
Clusters []string |
|
|
|
Zone string |
|
|
|
Zone string |
|
|
|
Subset int |
|
|
|
Subset int |
|
|
|
NonBlock bool |
|
|
|
NonBlock bool |
|
|
|
|
|
|
|
KeepAliveInterval xtime.Duration |
|
|
|
|
|
|
|
KeepAliveTimeout xtime.Duration |
|
|
|
|
|
|
|
KeepAliveWithoutStream bool |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// Client is the framework's client side instance, it contains the ctx, opt and interceptors.
|
|
|
|
// Client is the framework's client side instance, it contains the ctx, opt and interceptors.
|
|
|
@ -186,6 +191,12 @@ func (c *Client) SetConfig(conf *ClientConfig) (err error) { |
|
|
|
if conf.Subset <= 0 { |
|
|
|
if conf.Subset <= 0 { |
|
|
|
conf.Subset = 50 |
|
|
|
conf.Subset = 50 |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
if conf.KeepAliveInterval <= 0 { |
|
|
|
|
|
|
|
conf.KeepAliveInterval = xtime.Duration(time.Second * 60) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
if conf.KeepAliveTimeout <= 0 { |
|
|
|
|
|
|
|
conf.KeepAliveTimeout = xtime.Duration(time.Second * 20) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// FIXME(maojian) check Method dial/timeout
|
|
|
|
// FIXME(maojian) check Method dial/timeout
|
|
|
|
c.mutex.Lock() |
|
|
|
c.mutex.Lock() |
|
|
|