This example demonstrates how to set the request timeout duration when initiating a call from the Dubbo-go client. You can view the complete example source code here.
When creating a client, you can set a global timeout using the client.WithRequestTimeout()
method (shared by all service proxies using this client).
You can also create service-level timeout using client.WithRequestTimeout()
(all method calls initiated from the following service proxy svc
will use this timeout).
Additionally, you can specify a timeout when making the call using client.WithCallRequestTimeout()
.
From top to bottom, the priority of the above three methods increases, with client.WithCallRequestTimeout()
having the highest priority.
Source file path: dubbo-go-sample/timeout/proto/greet.proto
The Greet
method responds directly, while the GreetTimeout
method waits for five seconds before responding (simulating a timeout).
Source file path: dubbo-go-sample/timeout/go-server/handler.go
Client file, creating a client, setting the timeout to 3s, requesting Greet
and GreetTimeout
, and outputting the response results.
Source file path: dubbo-go-sample/timeout/go-client/client.go
Start the server first, then start the client. You will observe that the GreetTimeout
request times out while the Greet
request responds normally.