RPC Configuration

[!TIP] This document is machine-translated by Google. If you find grammatical and semantic errors, and the document description is not clear, please PR

The rpc configuration controls various functions of an rpc service, including but not limited to listening address, etcd configuration, timeout, fuse configuration, etc. Below we will use a common rpc service configuration to illustrate.

Configuration instructions

  1. Config struct {
  2. zrpc.RpcServerConf
  3. CacheRedis cache.CacheConf // Redis cache configuration, see the api configuration instructions for details, and I won’t go into details here
  4. Mysql struct { // mysql database access configuration, see api configuration instructions for details, not repeat here
  5. DataSource string
  6. }
  7. }

zrpc.RpcServerConf

  1. RpcServerConf struct {
  2. service.ServiceConf // mysql database access configuration, see api configuration instructions for details, not repeat here
  3. ListenOn string // rpc listening address and port, such as: 127.0.0.1:8888
  4. Etcd discov.EtcdConf `json:",optional"` // etcd related configuration
  5. Auth bool `json:",optional"` // Whether to enable Auth, if yes, Redis is required
  6. Redis redis.RedisKeyConf `json:",optional"` // Auth verification
  7. StrictControl bool `json:",optional"` // Whether it is Strict mode, if it is, the error is Auth failure, otherwise it can be considered as successful
  8. // pending forever is not allowed
  9. // never set it to 0, if zero, the underlying will set to 2s automatically
  10. Timeout int64 `json:",default=2000"` // Timeout control, unit: milliseconds
  11. CpuThreshold int64 `json:",default=900,range=[0:1000]"` // CPU load reduction threshold, the default is 900, the allowable setting range is 0 to 1000
  12. }

discov.EtcdConf

  1. type EtcdConf struct {
  2. Hosts []string // etcd host array
  3. Key string // rpc registration key
  4. }

redis.RedisKeyConf

  1. RedisConf struct {
  2. Host string // redis host
  3. Type string `json:",default=node,options=node|cluster"` // redis type
  4. Pass string `json:",optional"` // redis password
  5. }
  6. RedisKeyConf struct {
  7. RedisConf
  8. Key string `json:",optional"` // Verification key
  9. }