This is an automated email from the ASF dual-hosted git repository.
alexstocks pushed a commit to branch develop
in repository https://gitbox.apache.org/repos/asf/dubbo-go.git
The following commit(s) were added to refs/heads/develop by this push:
new d80526a45 Removed the dependency of dubbo, jsonrpc, and dubbo3 on
config in some protocols (#2909)
d80526a45 is described below
commit d80526a4524489c8b7a47f3b64a27a9bfb048c3e
Author: 1kasa <[email protected]>
AuthorDate: Mon Jun 9 07:56:24 2025 +0800
Removed the dependency of dubbo, jsonrpc, and dubbo3 on config in some
protocols (#2909)
* handle conflict
# Conflicts:
# client/options.go
# common/constant/default.go
# common/constant/key.go
* sort import
* handle conflict
---
client/action.go | 2 ++
common/constant/key.go | 3 ++-
dubbo.go | 2 +-
protocol/dubbo/dubbo_invoker.go | 7 +++++++
protocol/dubbo3/common_test.go | 1 +
protocol/dubbo3/dubbo3_invoker.go | 23 +++++++++++++++++++----
protocol/dubbo3/dubbo3_protocol.go | 5 +++++
protocol/jsonrpc/jsonrpc_protocol.go | 11 +++++++++--
protocol/jsonrpc/jsonrpc_protocol_test.go | 3 +++
protocol/triple/dubbo3_invoker.go | 6 ++++++
10 files changed, 55 insertions(+), 8 deletions(-)
diff --git a/client/action.go b/client/action.go
index 91eda4eb2..00a059ae2 100644
--- a/client/action.go
+++ b/client/action.go
@@ -131,6 +131,7 @@ func (refOpts *ReferenceOptions) refer(srv
common.RPCService, info *ClientInfo)
common.WithParams(refOpts.getURLMap()),
common.WithParamsValue(constant.BeanNameKey, refOpts.id),
common.WithParamsValue(constant.MetadataTypeKey,
refOpts.metaDataType),
+ // TODO: remove TimeoutKey after old confid removed
common.WithParamsValue(constant.TimeoutKey,
refOpts.Consumer.RequestTimeout),
// TODO: Deprecated:use TripleConfig
@@ -145,6 +146,7 @@ func (refOpts *ReferenceOptions) refer(srv
common.RPCService, info *ClientInfo)
// for new triple non-IDL mode
// TODO: remove ISIDL after old triple removed
common.WithParamsValue(constant.IDLMode, ref.IDLMode),
+ common.WithAttribute(constant.ConsumerConfigKey,
refOpts.Consumer),
)
// for new triple IDL mode
diff --git a/common/constant/key.go b/common/constant/key.go
index 828008457..af7d71adf 100644
--- a/common/constant/key.go
+++ b/common/constant/key.go
@@ -70,7 +70,8 @@ const (
// TODO: remove IDLMode after old triple removed
IDLMode = "IDL-mode"
- TripleConfigKey = "triple-config"
+ TripleConfigKey = "triple-config"
+ ConsumerConfigKey = "consumer-config"
)
// TODO: remove this after old triple removed
diff --git a/dubbo.go b/dubbo.go
index da3231b39..10531f304 100644
--- a/dubbo.go
+++ b/dubbo.go
@@ -290,6 +290,6 @@ func SetProviderService(svc common.RPCService) {
}
}
-func GetConsumerService(interfaceName string) (*client.Connection, error) {
+func GetConsumerConnection(interfaceName string) (*client.Connection, error) {
return consumerServices[interfaceName].GetConnection()
}
diff --git a/protocol/dubbo/dubbo_invoker.go b/protocol/dubbo/dubbo_invoker.go
index 0530ca090..7c2eac811 100644
--- a/protocol/dubbo/dubbo_invoker.go
+++ b/protocol/dubbo/dubbo_invoker.go
@@ -35,6 +35,7 @@ import (
"dubbo.apache.org/dubbo-go/v3/common"
"dubbo.apache.org/dubbo-go/v3/common/constant"
"dubbo.apache.org/dubbo-go/v3/config"
+ "dubbo.apache.org/dubbo-go/v3/global"
"dubbo.apache.org/dubbo-go/v3/protocol/base"
"dubbo.apache.org/dubbo-go/v3/protocol/invocation"
"dubbo.apache.org/dubbo-go/v3/protocol/result"
@@ -56,7 +57,13 @@ type DubboInvoker struct {
// NewDubboInvoker constructor
func NewDubboInvoker(url *common.URL, client *remoting.ExchangeClient)
*DubboInvoker {
+ // TODO: Temporary compatibility with old APIs, can be removed later
rt := config.GetConsumerConfig().RequestTimeout
+ if consumerConfRaw, ok := url.GetAttribute(constant.ConsumerConfigKey);
ok {
+ if consumerConf, ok :=
consumerConfRaw.(*global.ConsumerConfig); ok {
+ rt = consumerConf.RequestTimeout
+ }
+ }
timeout := url.GetParamDuration(constant.TimeoutKey, rt)
di := &DubboInvoker{
diff --git a/protocol/dubbo3/common_test.go b/protocol/dubbo3/common_test.go
index 998dcf717..643e0e041 100644
--- a/protocol/dubbo3/common_test.go
+++ b/protocol/dubbo3/common_test.go
@@ -32,6 +32,7 @@ import (
"dubbo.apache.org/dubbo-go/v3/protocol/invocation"
)
+// TODO: After the config is removed, remove the test
// userd dubbo3 biz service
func addService() {
config.SetProviderService(newGreeterProvider())
diff --git a/protocol/dubbo3/dubbo3_invoker.go
b/protocol/dubbo3/dubbo3_invoker.go
index 8c5ac5cfc..b6f18d2e8 100644
--- a/protocol/dubbo3/dubbo3_invoker.go
+++ b/protocol/dubbo3/dubbo3_invoker.go
@@ -71,13 +71,27 @@ type DubboInvoker struct {
// NewDubboInvoker constructor
func NewDubboInvoker(url *common.URL) (*DubboInvoker, error) {
- rt := config.GetConsumerConfig().RequestTimeout
-
+ var (
+ rt string
+ consumerService any
+ )
+ // TODO: Temporary compatibility with old APIs, can be removed later
+ rt = config.GetConsumerConfig().RequestTimeout
+ if consumerConfRaw, ok := url.GetAttribute(constant.ConsumerConfigKey);
ok {
+ if consumerConf, ok :=
consumerConfRaw.(*global.ConsumerConfig); ok {
+ rt = consumerConf.RequestTimeout
+ }
+ }
+ // TODO: If you do not need to be compatible with the old API, you can
directly use url.GetAttribute(constant.ConsumerConfigKey) as the timeout
timeout := url.GetParamDuration(constant.TimeoutKey, rt)
// for triple pb serialization. The bean name from provider is the
provider reference key,
- // which can't locate the target consumer stub, so we use interface
key..
+ // which can't locate the target consumer stub, so we use interface key.
interfaceKey := url.GetParam(constant.InterfaceKey, "")
- consumerService :=
config.GetConsumerServiceByInterfaceName(interfaceKey)
+ //TODO: Temporary compatibility with old APIs, can be removed later
+ consumerService = config.GetConsumerServiceByInterfaceName(interfaceKey)
+ if rpcService, ok := url.GetAttribute(constant.RpcServiceKey); ok {
+ consumerService = rpcService
+ }
dubboSerializerType := url.GetParam(constant.SerializationKey,
constant.ProtobufSerialization)
triCodecType := tripleConstant.CodecType(dubboSerializerType)
@@ -101,6 +115,7 @@ func NewDubboInvoker(url *common.URL) (*DubboInvoker,
error) {
opts = append(opts,
triConfig.WithGRPCMaxCallRecvMessageSize(maxCallRecvMsgSize))
opts = append(opts,
triConfig.WithGRPCMaxCallSendMessageSize(maxCallSendMsgSize))
+ //TODO: Temporary compatibility with old APIs, can be removed later
tracingKey := url.GetParam(constant.TracingConfigKey, "")
if tracingKey != "" {
tracingConfig := config.GetTracingConfig(tracingKey)
diff --git a/protocol/dubbo3/dubbo3_protocol.go
b/protocol/dubbo3/dubbo3_protocol.go
index b8ee4aeeb..5d63ba0d8 100644
--- a/protocol/dubbo3/dubbo3_protocol.go
+++ b/protocol/dubbo3/dubbo3_protocol.go
@@ -86,7 +86,11 @@ func (dp *DubboProtocol) Export(invoker base.Invoker)
base.Exporter {
key := url.GetParam(constant.BeanNameKey, "")
var service any
+ //TODO: Temporary compatibility with old APIs, can be removed later
service = config.GetProviderService(key)
+ if rpcService, ok := url.GetAttribute(constant.RpcServiceKey); ok {
+ service = rpcService
+ }
serializationType := url.GetParam(constant.SerializationKey,
constant.ProtobufSerialization)
var triSerializationType tripleConstant.CodecType
@@ -225,6 +229,7 @@ func (dp *DubboProtocol) openServer(url *common.URL,
tripleCodecType tripleConst
triConfig.WithLocation(url.Location),
triConfig.WithLogger(logger.GetLogger()),
}
+ //TODO: Temporary compatibility with old APIs, can be removed later
tracingKey := url.GetParam(constant.TracingConfigKey, "")
if tracingKey != "" {
tracingConfig := config.GetTracingConfig(tracingKey)
diff --git a/protocol/jsonrpc/jsonrpc_protocol.go
b/protocol/jsonrpc/jsonrpc_protocol.go
index 5abd6d711..a091fd55c 100644
--- a/protocol/jsonrpc/jsonrpc_protocol.go
+++ b/protocol/jsonrpc/jsonrpc_protocol.go
@@ -32,6 +32,7 @@ import (
"dubbo.apache.org/dubbo-go/v3/common/constant"
"dubbo.apache.org/dubbo-go/v3/common/extension"
"dubbo.apache.org/dubbo-go/v3/config"
+ "dubbo.apache.org/dubbo-go/v3/global"
"dubbo.apache.org/dubbo-go/v3/protocol/base"
)
@@ -79,9 +80,15 @@ func (jp *JsonrpcProtocol) Export(invoker base.Invoker)
base.Exporter {
// Refer a remote JSON PRC service from registry
func (jp *JsonrpcProtocol) Refer(url *common.URL) base.Invoker {
- rtStr := config.GetConsumerConfig().RequestTimeout
+ // TODO: Temporary compatibility with old APIs, can be removed later
+ rt := config.GetConsumerConfig().RequestTimeout
+ if consumerConfRaw, ok := url.GetAttribute(constant.ConsumerConfigKey);
ok {
+ if consumerConf, ok :=
consumerConfRaw.(*global.ConsumerConfig); ok {
+ rt = consumerConf.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)
+ requestTimeout := url.GetParamDuration(constant.TimeoutKey, rt)
// New Json rpc Invoker
invoker := NewJsonrpcInvoker(url, NewHTTPClient(&HTTPOptions{
HandshakeTimeout: time.Second, // todo config timeout
config.GetConsumerConfig().ConnectTimeout,
diff --git a/protocol/jsonrpc/jsonrpc_protocol_test.go
b/protocol/jsonrpc/jsonrpc_protocol_test.go
index 5313bc663..5990689ce 100644
--- a/protocol/jsonrpc/jsonrpc_protocol_test.go
+++ b/protocol/jsonrpc/jsonrpc_protocol_test.go
@@ -64,6 +64,7 @@ func TestJsonrpcProtocolExport(t *testing.T) {
assert.False(t, ok)
}
+// TODO: After discarding the config package, delete the test
func TestJsonrpcProtocolRefer(t *testing.T) {
// Refer
proto := GetProtocol()
@@ -73,10 +74,12 @@ func TestJsonrpcProtocolRefer(t *testing.T) {
"module=dubbogo+user-info+server&org=ikurento.com&owner=ZX&pid=1447&revision=0.0.1&"
+
"side=provider&timeout=3000×tamp=1556509797245")
assert.NoError(t, err)
+ // TODO: Temporary compatibility with old APIs, can be removed later
con := config.ConsumerConfig{
RequestTimeout: "5s",
}
config.SetConsumerConfig(con)
+
invoker := proto.Refer(url)
// make sure url
diff --git a/protocol/triple/dubbo3_invoker.go
b/protocol/triple/dubbo3_invoker.go
index 710b1e9f3..888997eac 100644
--- a/protocol/triple/dubbo3_invoker.go
+++ b/protocol/triple/dubbo3_invoker.go
@@ -71,7 +71,13 @@ type DubboInvoker struct {
// NewDubbo3Invoker constructor
func NewDubbo3Invoker(url *common.URL) (*DubboInvoker, error) {
+ // TODO: Temporary compatibility with old APIs, can be removed later
rt := config.GetConsumerConfig().RequestTimeout
+ if consumerConfRaw, ok := url.GetAttribute(constant.ConsumerConfigKey);
ok {
+ if consumerConf, ok :=
consumerConfRaw.(*global.ConsumerConfig); ok {
+ rt = consumerConf.RequestTimeout
+ }
+ }
timeout := url.GetParamDuration(constant.TimeoutKey, rt)
// for triple pb serialization. The bean name from provider is the
provider reference key,