rpc配置控制著一個rpc服務(wù)的各種功能,包含但不限于監(jiān)聽地址,etcd配置,超時,熔斷配置等,下面我們以一個常見的rpc服務(wù)配置來進行說明。
Config struct {
zrpc.RpcServerConf
CacheRedis cache.CacheConf // redis緩存配置,詳情見api配置說明,這里不贅述
Mysql struct { // mysql數(shù)據(jù)庫訪問配置,詳情見api配置說明,這里不贅述
DataSource string
}
}
RpcServerConf struct {
service.ServiceConf // 服務(wù)配置,詳情見api配置說明,這里不贅述
ListenOn string // rpc監(jiān)聽地址和端口,如:127.0.0.1:8888
Etcd discov.EtcdConf `json:",optional"` // etcd相關(guān)配置
Auth bool `json:",optional"` // 是否開啟Auth,如果是則Redis為必填
Redis redis.RedisKeyConf `json:",optional"` // Auth驗證
StrictControl bool `json:",optional"` // 是否Strict模式,如果是則遇到錯誤是Auth失敗,否則可以認為成功
// pending forever is not allowed
// never set it to 0, if zero, the underlying will set to 2s automatically
Timeout int64 `json:",default=2000"` // 超時控制,單位:毫秒
CpuThreshold int64 `json:",default=900,range=[0:1000]"` cpu降載閾值,默認900,可允許設(shè)置范圍0到1000
}
type EtcdConf struct {
Hosts []string // etcd host數(shù)組
Key string // rpc注冊key
}
RedisConf struct {
Host string // redis 主機
Type string `json:",default=node,options=node|cluster"` // redis類型
Pass string `json:",optional"` // redis密碼
}
RedisKeyConf struct {
RedisConf
Key string `json:",optional"` // 驗證key
}
更多建議: