dubbo:
consumer:
request-timeout: 15s # 配置客户端超时
Dubbo-go 应用默认 RPC 超时为 3s,请求超时后,客户端将会返回error 为 context deadline exceeded 的错误。在本任务中,您需要首先修改 demo 应用的 server 函数为较长耗时,然后查看客户端的超时报错;再通过配置客户端超时,使得耗时函数可以正常调用。
go-server/cmd/server.go: 修改 demo 应用 server 的函数为耗时 10s 的函数
func (s *GreeterProvider) SayHello(ctx context.Context, in *api.HelloRequest) (*api.User, error) {
logger.Infof("Dubbo3 GreeterProvider get user name = %s\n", in.Name)
time.Sleep(time.Second*10) // sleep 10s
return &api.User{Name: "Hello " + in.Name, Id: "12345", Age: 21}, nil
}
客户端发起调用,观察错误日志
ERROR cmd/client.go:47 context deadline exceeded
go-client/conf/dubbogo.yaml: 客户端修改超时
dubbo:
consumer:
request-timeout: 15s # 配置客户端超时
references:
GreeterClientImpl:
protocol: tri
url: "tri://localhost:20000"
interface: "" # read from pb
再次通过客户端发起调用,观察日志,正常返回:
client response result: name:"Hello laurence" id:"12345" age:21