W3Cschool
恭喜您成為首批注冊(cè)用戶
獲得88經(jīng)驗(yàn)值獎(jiǎng)勵(lì)
rpc配置控制著一個(gè)rpc服務(wù)的各種功能,包含但不限于監(jiān)聽(tīng)地址,etcd配置,超時(shí),熔斷配置等,下面我們以一個(gè)常見(jiàn)的rpc服務(wù)配置來(lái)進(jìn)行說(shuō)明。
Config struct {
zrpc.RpcServerConf
CacheRedis cache.CacheConf // redis緩存配置,詳情見(jiàn)api配置說(shuō)明,這里不贅述
Mysql struct { // mysql數(shù)據(jù)庫(kù)訪問(wèn)配置,詳情見(jiàn)api配置說(shuō)明,這里不贅述
DataSource string
}
}
RpcServerConf struct {
service.ServiceConf // 服務(wù)配置,詳情見(jiàn)api配置說(shuō)明,這里不贅述
ListenOn string // rpc監(jiān)聽(tīng)地址和端口,如:127.0.0.1:8888
Etcd discov.EtcdConf `json:",optional"` // etcd相關(guān)配置
Auth bool `json:",optional"` // 是否開(kāi)啟Auth,如果是則Redis為必填
Redis redis.RedisKeyConf `json:",optional"` // Auth驗(yàn)證
StrictControl bool `json:",optional"` // 是否Strict模式,如果是則遇到錯(cuò)誤是Auth失敗,否則可以認(rèn)為成功
// pending forever is not allowed
// never set it to 0, if zero, the underlying will set to 2s automatically
Timeout int64 `json:",default=2000"` // 超時(shí)控制,單位:毫秒
CpuThreshold int64 `json:",default=900,range=[0:1000]"` cpu降載閾值,默認(rèn)900,可允許設(shè)置范圍0到1000
}
type EtcdConf struct {
Hosts []string // etcd host數(shù)組
Key string // rpc注冊(cè)key
}
RedisConf struct {
Host string // redis 主機(jī)
Type string `json:",default=node,options=node|cluster"` // redis類型
Pass string `json:",optional"` // redis密碼
}
RedisKeyConf struct {
RedisConf
Key string `json:",optional"` // 驗(yàn)證key
}
Copyright©2021 w3cschool編程獅|閩ICP備15016281號(hào)-3|閩公網(wǎng)安備35020302033924號(hào)
違法和不良信息舉報(bào)電話:173-0602-2364|舉報(bào)郵箱:jubao@eeedong.com
掃描二維碼
下載編程獅App
編程獅公眾號(hào)
聯(lián)系方式:
更多建議: