You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@dubbo.apache.org by al...@apache.org on 2022/01/16 13:17:11 UTC
[dubbo-go] branch 3.0 updated: refactor json rpc request timeout (#1713)
This is an automated email from the ASF dual-hosted git repository.
alexstocks pushed a commit to branch 3.0
in repository https://gitbox.apache.org/repos/asf/dubbo-go.git
The following commit(s) were added to refs/heads/3.0 by this push:
new 08e4387 refactor json rpc request timeout (#1713)
08e4387 is described below
commit 08e43870bacf619cf6298ad2dfb37a49ee02330a
Author: sunrui1225 <sr...@163.com>
AuthorDate: Sun Jan 16 21:17:03 2022 +0800
refactor json rpc request timeout (#1713)
---
protocol/jsonrpc/jsonrpc_protocol.go | 16 ++++++----------
1 file changed, 6 insertions(+), 10 deletions(-)
diff --git a/protocol/jsonrpc/jsonrpc_protocol.go b/protocol/jsonrpc/jsonrpc_protocol.go
index 1ad7ffb..d5bcf96 100644
--- a/protocol/jsonrpc/jsonrpc_protocol.go
+++ b/protocol/jsonrpc/jsonrpc_protocol.go
@@ -25,8 +25,10 @@ import (
import (
"dubbo.apache.org/dubbo-go/v3/common"
+ "dubbo.apache.org/dubbo-go/v3/common/constant"
"dubbo.apache.org/dubbo-go/v3/common/extension"
"dubbo.apache.org/dubbo-go/v3/common/logger"
+ "dubbo.apache.org/dubbo-go/v3/config"
"dubbo.apache.org/dubbo-go/v3/protocol"
)
@@ -74,16 +76,10 @@ func (jp *JsonrpcProtocol) Export(invoker protocol.Invoker) protocol.Exporter {
// Refer a remote JSON PRC service from registry
func (jp *JsonrpcProtocol) Refer(url *common.URL) protocol.Invoker {
- // default requestTimeout
- // todo config timeout
- requestTimeout := time.Duration(3 * time.Second) //config.GetConsumerConfig().RequestTimeout
-
- // todo config timeout
- requestTimeoutStr := "3s" //url.GetParam(constant.TIMEOUT_KEY, config.GetConsumerConfig().Request_Timeout)
- if t, err := time.ParseDuration(requestTimeoutStr); err == nil {
- requestTimeout = t
- }
-
+ rtStr := config.GetConsumerConfig().RequestTimeout
+ // the read order of requestTimeout is from url , if nil then from consumer config , if nil then default 3s. requestTimeout can be dynamically updated from config center.
+ requestTimeout := url.GetParamDuration(constant.TimeoutKey, rtStr)
+ // New Json rpc Invoker
invoker := NewJsonrpcInvoker(url, NewHTTPClient(&HTTPOptions{
HandshakeTimeout: time.Second, // todo config timeout config.GetConsumerConfig().ConnectTimeout,
HTTPTimeout: requestTimeout,