Timeouts
Kitex supports RPC timeout and connection timeout, both of which support client-level and invocation-level configurations.
RPC Timeout
- You can specify RPC timeout in client initialization, it will works for all RPC started by this client by default.
import "github.com/cloudwego/kitex/client"
...
rpcTimeout := client.WithRPCTimeout(3*time.Second)
client, err := echo.NewClient("echo", rpcTimeout)
if err != nil {
log.Fatal(err)
}
- And you can also specify timeout for a specific RPC call.
import "github.com/cloudwego/kitex/client/callopt"
...
rpcTimeout := callopt.WithRPCTimeout(3*time.Second)
resp, err := client.Echo(context.Background(), req, rpcTimeout)
if err != nil {
log.Fatal(err)
}
Connection Timeout
- You can specify connection timeout in client initialization, it will works for all RPC started by this client by default.
import "github.com/cloudwego/kitex/client"
...
connTimeout := client.WithConnectTimeout(50*time.Millisecond)
client, err := echo.NewClient("echo", connTimeout)
if err != nil {
log.Fatal(err)
}
- And you can also specify timeout for a specific RPC call.
import "github.com/cloudwego/kitex/client/callopt"
...
connTimeout := callopt.WithConnectTimeout(50*time.Millisecond)
resp, err := client.Echo(context.Background(), req, connTimeout)
if err != nil {
log.Fatal(err)
}
Last modified
July 3, 2023
: Update response.md (0a36fb2)