feat: 设置rpc timeout

This commit is contained in:
wolter 2024-11-08 11:47:30 +08:00
parent 76f7b9e15c
commit 9c125f5562
3 changed files with 7 additions and 0 deletions

View File

@ -5,6 +5,7 @@ Cache:
- Host: 47.97.27.195:6379 - Host: 47.97.27.195:6379
Pass: lansexiongdi@666 Pass: lansexiongdi@666
Nacos: Nacos:
Timeout: 5000
Endpoints: Endpoints:
- 120.55.12.245:10001 - 120.55.12.245:10001
Sys: Sys:

View File

@ -31,6 +31,7 @@ type Rpc struct {
} }
type Nacos struct { type Nacos struct {
Timeout int64
Endpoints []string Endpoints []string
} }

View File

@ -18,8 +18,13 @@ type ServiceContext struct {
} }
func NewServiceContext(c config.Config) *ServiceContext { func NewServiceContext(c config.Config) *ServiceContext {
var timeOut int64 = 2000
if c.Nacos.Timeout > 2000 {
timeOut = c.Nacos.Timeout
}
client := transferClient.NewTransfer(zrpc.MustNewClient(zrpc.RpcClientConf{ client := transferClient.NewTransfer(zrpc.MustNewClient(zrpc.RpcClientConf{
Endpoints: c.Nacos.Endpoints, Endpoints: c.Nacos.Endpoints,
Timeout: timeOut,
})) }))
sqlConn := sqlx.NewMysql(c.DB.Master.DataSource) sqlConn := sqlx.NewMysql(c.DB.Master.DataSource)