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 8e9a7135a Refactor: remove config in grpc and dubbo3 (#3231)
8e9a7135a is described below

commit 8e9a7135af48a079c7429a70489f2d6a719ecbbb
Author: 翎 <[email protected]>
AuthorDate: Sun Mar 22 23:34:34 2026 +0800

    Refactor: remove config in grpc and dubbo3 (#3231)
    
    * feat(dubbo3): remove config dependency in invoke
---
 protocol/dubbo3/dubbo3_invoker.go   | 58 +++++++++++++-------------
 protocol/dubbo3/dubbo3_protocol.go  | 66 ++++++++++++++---------------
 protocol/grpc/client.go             | 83 +++++++++++++------------------------
 protocol/grpc/client_test.go        |  3 ++
 protocol/grpc/grpc_invoker_test.go  |  5 ++-
 protocol/grpc/grpc_protocol_test.go |  2 +
 protocol/grpc/server.go             | 74 ++++++++++-----------------------
 7 files changed, 119 insertions(+), 172 deletions(-)

diff --git a/protocol/dubbo3/dubbo3_invoker.go 
b/protocol/dubbo3/dubbo3_invoker.go
index 8b3ffc69a..cc058cd07 100644
--- a/protocol/dubbo3/dubbo3_invoker.go
+++ b/protocol/dubbo3/dubbo3_invoker.go
@@ -40,7 +40,6 @@ import (
 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/result"
@@ -72,20 +71,19 @@ func NewDubboInvoker(url *common.URL) (*DubboInvoker, 
error) {
                rt              string
                consumerService any
        )
-       // TODO: Temporary compatibility with old APIs, can be removed later
-       rt = config.GetConsumerConfig().RequestTimeout
+       rt = ""
        if consumerConfRaw, ok := url.GetAttribute(constant.ConsumerConfigKey); 
ok {
-               if consumerConf, ok := 
consumerConfRaw.(*global.ConsumerConfig); ok {
+               if consumerConf, ok := 
consumerConfRaw.(*global.ConsumerConfig); ok && consumerConf.RequestTimeout != 
"" {
                        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
+       if rt == "" {
+               rt = global.DefaultConsumerConfig().RequestTimeout
+       }
        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.
-       interfaceKey := url.GetParam(constant.InterfaceKey, "")
-       //TODO: Temporary compatibility with old APIs, can be removed later
-       consumerService = config.GetConsumerServiceByInterfaceName(interfaceKey)
+       consumerService = nil
        if rpcService, ok := url.GetAttribute(constant.RpcServiceKey); ok {
                consumerService = rpcService
        }
@@ -112,20 +110,29 @@ 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)
-               if tracingConfig != nil {
+       if tracingConfRaw, ok := url.GetAttribute(constant.TracingConfigKey); 
ok {
+               tracingConfig, ok := tracingConfRaw.(*global.TracingConfig)
+               if !ok {
+                       logger.Warnf("invalid tracing config type %T, expected 
*global.TracingConfig", tracingConfRaw)
+               } else if tracingConfig != nil {
                        if tracingConfig.Name == "jaeger" {
-                               if tracingConfig.ServiceName == "" {
-                                       tracingConfig.ServiceName = 
config.GetApplicationConfig().Name
+                               serviceName := tracingConfig.ServiceName
+                               if serviceName == "" {
+                                       serviceName = 
url.GetParam(constant.ApplicationKey, "")
+                               }
+                               useAgent := false
+                               if tracingConfig.UseAgent != nil {
+                                       useAgent = *tracingConfig.UseAgent
+                               }
+                               if serviceName == "" {
+                                       logger.Warnf("jaeger tracing skipped: 
no service name available for %s", url.String())
+                               } else {
+                                       opts = append(opts, 
triConfig.WithJaegerConfig(
+                                               tracingConfig.Address,
+                                               serviceName,
+                                               useAgent,
+                                       ))
                                }
-                               opts = append(opts, triConfig.WithJaegerConfig(
-                                       tracingConfig.Address,
-                                       tracingConfig.ServiceName,
-                                       *tracingConfig.UseAgent,
-                               ))
                        } else {
                                logger.Warnf("unsupported tracing name %s, now 
triple only support jaeger", tracingConfig.Name)
                        }
@@ -134,16 +141,7 @@ func NewDubboInvoker(url *common.URL) (*DubboInvoker, 
error) {
 
        triOption := triConfig.NewTripleOption(opts...)
 
-       // TODO: remove config TLSConfig
-       // delete this branch
-       tlsConfig := config.GetRootConfig().TLSConfig
-       if tlsConfig != nil {
-               triOption.CACertFile = tlsConfig.CACertFile
-               triOption.TLSCertFile = tlsConfig.TLSCertFile
-               triOption.TLSKeyFile = tlsConfig.TLSKeyFile
-               triOption.TLSServerName = tlsConfig.TLSServerName
-               logger.Infof("DUBBO3 Client initialized the TLSConfig 
configuration")
-       } else if tlsConfRaw, ok := url.GetAttribute(constant.TLSConfigKey); ok 
{
+       if tlsConfRaw, ok := url.GetAttribute(constant.TLSConfigKey); ok {
                // use global TLSConfig handle tls
                tlsConf, ok := tlsConfRaw.(*global.TLSConfig)
                if !ok {
diff --git a/protocol/dubbo3/dubbo3_protocol.go 
b/protocol/dubbo3/dubbo3_protocol.go
index 5d63ba0d8..da878e847 100644
--- a/protocol/dubbo3/dubbo3_protocol.go
+++ b/protocol/dubbo3/dubbo3_protocol.go
@@ -40,7 +40,6 @@ import (
 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"
@@ -50,8 +49,6 @@ import (
 var protocolOnce sync.Once
 
 func init() {
-       // todo(DMwangnima): deprecated
-       //extension.SetProtocol(tripleConstant.TRIPLE, GetProtocol)
        protocolOnce = sync.Once{}
 }
 
@@ -80,17 +77,15 @@ func NewDubboProtocol() *DubboProtocol {
 func (dp *DubboProtocol) Export(invoker base.Invoker) base.Exporter {
        url := invoker.GetURL()
        serviceKey := url.ServiceKey()
-       exporter := NewDubboExporter(serviceKey, invoker, dp.ExporterMap(), 
dp.serviceMap)
-       dp.SetExporterMap(serviceKey, exporter)
-       logger.Infof("[Triple Protocol] Export service: %s", url.String())
 
        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
        }
+       if service == nil {
+               panic(fmt.Sprintf("[Triple Protocol] no rpc service found in 
url attribute %s for service key: %s", constant.RpcServiceKey, key))
+       }
 
        serializationType := url.GetParam(constant.SerializationKey, 
constant.ProtobufSerialization)
        var triSerializationType tripleConstant.CodecType
@@ -131,6 +126,10 @@ func (dp *DubboProtocol) Export(invoker base.Invoker) 
base.Exporter {
                triSerializationType = 
tripleConstant.CodecType(serializationType)
        }
 
+       exporter := NewDubboExporter(serviceKey, invoker, dp.ExporterMap(), 
dp.serviceMap)
+       dp.SetExporterMap(serviceKey, exporter)
+       logger.Infof("[Triple Protocol] Export service: %s", url.String())
+
        dp.serviceMap.Store(url.GetParam(constant.InterfaceKey, ""), service)
 
        // try start server
@@ -229,22 +228,30 @@ 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)
-               if tracingConfig != nil {
-                       if tracingConfig.ServiceName == "" {
-                               tracingConfig.ServiceName = 
config.GetApplicationConfig().Name
-                       }
-                       switch tracingConfig.Name {
-                       case "jaeger":
-                               opts = append(opts, triConfig.WithJaegerConfig(
-                                       tracingConfig.Address,
-                                       tracingConfig.ServiceName,
-                                       *tracingConfig.UseAgent,
-                               ))
-                       default:
+       if tracingConfRaw, tracingAttrOk := 
url.GetAttribute(constant.TracingConfigKey); tracingAttrOk {
+               tracingConfig, tracingConfigOk := 
tracingConfRaw.(*global.TracingConfig)
+               if !tracingConfigOk {
+                       logger.Warnf("invalid tracing config type %T, expected 
*global.TracingConfig", tracingConfRaw)
+               } else if tracingConfig != nil {
+                       if tracingConfig.Name == "jaeger" {
+                               serviceName := tracingConfig.ServiceName
+                               if serviceName == "" {
+                                       serviceName = 
url.GetParam(constant.ApplicationKey, "")
+                               }
+                               useAgent := false
+                               if tracingConfig.UseAgent != nil {
+                                       useAgent = *tracingConfig.UseAgent
+                               }
+                               if serviceName == "" {
+                                       logger.Warnf("jaeger tracing skipped: 
no service name available for %s", url.String())
+                               } else {
+                                       opts = append(opts, 
triConfig.WithJaegerConfig(
+                                               tracingConfig.Address,
+                                               serviceName,
+                                               useAgent,
+                                       ))
+                               }
+                       } else {
                                logger.Warnf("unsupported tracing name %s, now 
triple only support jaeger", tracingConfig.Name)
                        }
                }
@@ -263,16 +270,7 @@ func (dp *DubboProtocol) openServer(url *common.URL, 
tripleCodecType tripleConst
 
        triOption := triConfig.NewTripleOption(opts...)
 
-       // TODO: remove config TLSConfig
-       // delete this branch
-       tlsConfig := config.GetRootConfig().TLSConfig
-       if tlsConfig != nil {
-               triOption.CACertFile = tlsConfig.CACertFile
-               triOption.TLSCertFile = tlsConfig.TLSCertFile
-               triOption.TLSKeyFile = tlsConfig.TLSKeyFile
-               triOption.TLSServerName = tlsConfig.TLSServerName
-               logger.Infof("DUBBO3 Server initialized the TLSConfig 
configuration")
-       } else if tlsConfRaw, tlsOk := url.GetAttribute(constant.TLSConfigKey); 
tlsOk {
+       if tlsConfRaw, tlsOk := url.GetAttribute(constant.TLSConfigKey); tlsOk {
                // use global TLSConfig handle tls
                tlsConf, RawOk := tlsConfRaw.(*global.TLSConfig)
                if !RawOk {
diff --git a/protocol/grpc/client.go b/protocol/grpc/client.go
index b4bd37025..9f1093571 100644
--- a/protocol/grpc/client.go
+++ b/protocol/grpc/client.go
@@ -19,6 +19,7 @@ package grpc
 
 import (
        "errors"
+       "fmt"
        "reflect"
        "sync"
        "time"
@@ -41,10 +42,8 @@ import (
 )
 
 import (
-       "dubbo.apache.org/dubbo-go/v3"
        "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"
        dubbotls "dubbo.apache.org/dubbo-go/v3/tls"
 )
@@ -79,9 +78,6 @@ func NewClient(url *common.URL) (*Client, error) {
                maxCallSendMsgSize = int(sendMsgSize)
        }
 
-       // consumer config client connectTimeout
-       //connectTimeout := config.GetConsumerConfig().ConnectTimeout
-
        dialOpts = append(dialOpts,
                grpc.WithBlock(),
                // todo config network timeout
@@ -95,22 +91,9 @@ func NewClient(url *common.URL) (*Client, error) {
                ),
        )
 
-       // TODO: remove config TLSConfig
-       // delete this branch
-       tlsConfig := config.GetRootConfig().TLSConfig
-       if tlsConfig != nil {
-               cfg, err := config.GetClientTlsConfig(&config.TLSConfig{
-                       CACertFile:    tlsConfig.CACertFile,
-                       TLSCertFile:   tlsConfig.TLSCertFile,
-                       TLSKeyFile:    tlsConfig.TLSKeyFile,
-                       TLSServerName: tlsConfig.TLSServerName,
-               })
-               logger.Infof("Grpc Client initialized the TLSConfig 
configuration")
-               if err != nil {
-                       return nil, err
-               }
-               dialOpts = append(dialOpts, 
grpc.WithTransportCredentials(credentials.NewTLS(cfg)))
-       } else if tlsConfRaw, ok := url.GetAttribute(constant.TLSConfigKey); ok 
{
+       var transportCreds credentials.TransportCredentials
+       transportCreds = insecure.NewCredentials()
+       if tlsConfRaw, ok := url.GetAttribute(constant.TLSConfigKey); ok {
                // use global TLSConfig handle tls
                tlsConf, ok := tlsConfRaw.(*global.TLSConfig)
                if !ok {
@@ -125,15 +108,11 @@ func NewClient(url *common.URL) (*Client, error) {
                        }
                        if cfg != nil {
                                logger.Infof("Grpc Client initialized the 
TLSConfig configuration")
-                               dialOpts = append(dialOpts, 
grpc.WithTransportCredentials(credentials.NewTLS(cfg)))
+                               transportCreds = credentials.NewTLS(cfg)
                        }
-               } else {
-                       dialOpts = append(dialOpts, 
grpc.WithTransportCredentials(insecure.NewCredentials()))
                }
-       } else {
-               // TODO: remove this else
-               dialOpts = append(dialOpts, 
grpc.WithTransportCredentials(insecure.NewCredentials()))
        }
+       dialOpts = append(dialOpts, 
grpc.WithTransportCredentials(transportCreds))
 
        conn, err := grpc.Dial(url.Location, dialOpts...)
        if err != nil {
@@ -142,14 +121,21 @@ func NewClient(url *common.URL) (*Client, error) {
        }
 
        key := url.GetParam(constant.InterfaceKey, "")
-       //TODO: Temporary compatibility with old APIs, can be removed later
-       consumerService := config.GetConsumerServiceByInterfaceName(key)
+       var consumerService any
+       if rpcService, ok := url.GetAttribute(constant.RpcServiceKey); ok {
+               consumerService = rpcService
+       }
        if consumerService == nil {
-               if rpcService, ok := url.GetAttribute(constant.RpcServiceKey); 
ok {
-                       consumerService = rpcService
-               }
+               conn.Close()
+               return nil, fmt.Errorf("grpc: no rpc service found for 
interface=%s", key)
        }
        invoker := getInvoker(consumerService, conn)
+       if invoker == nil {
+               err := fmt.Errorf("grpc client invoker is nil, interface=%s", 
key)
+               logger.Errorf("failed to get grpc client invoker: %v", err)
+               conn.Close()
+               return nil, err
+       }
 
        return &Client{
                ClientConn: conn,
@@ -158,9 +144,6 @@ func NewClient(url *common.URL) (*Client, error) {
 }
 
 func clientInit(url *common.URL) {
-       // load rootConfig from runtime
-       rootConfig := config.GetRootConfig()
-
        clientConfig := GetClientConfig()
        clientConf = &clientConfig
 
@@ -175,28 +158,18 @@ func clientInit(url *common.URL) {
                }
        }()
 
-       if rootConfig.Application == nil {
-               app := url.GetParam(constant.ApplicationKey, "")
-               if len(app) == 0 {
-                       return
-               }
+       protocolConfRaw, ok := url.GetAttribute(constant.ProtocolConfigKey)
+       if !ok {
+               return
+       }
+       protocolConf, ok := protocolConfRaw.(map[string]*global.ProtocolConfig)
+       if !ok {
+               logger.Warnf("protocolConfig assert failed")
+               return
        }
-
-       //TODO: Temporary compatibility with old APIs, can be removed later
-       protocolConf := 
dubbo.CompatGlobalProtocolConfigMap(rootConfig.Protocols)
        if protocolConf == nil {
-               if protocolConfRaw, ok := 
url.GetAttribute(constant.ProtocolConfigKey); ok {
-                       protocolConfig, ok := 
protocolConfRaw.(map[string]*global.ProtocolConfig)
-                       if !ok {
-                               logger.Warnf("protocolConfig assert failed")
-                               return
-                       }
-                       if protocolConfig == nil {
-                               logger.Warnf("protocolConfig is nil")
-                               return
-                       }
-                       protocolConf = protocolConfig
-               }
+               logger.Warnf("protocolConfig is nil")
+               return
        }
        grpcConf := protocolConf[GRPC]
        if grpcConf == nil {
diff --git a/protocol/grpc/client_test.go b/protocol/grpc/client_test.go
index 0091779b3..9d3f7b4b6 100644
--- a/protocol/grpc/client_test.go
+++ b/protocol/grpc/client_test.go
@@ -32,6 +32,7 @@ import (
 
 import (
        "dubbo.apache.org/dubbo-go/v3/common"
+       "dubbo.apache.org/dubbo-go/v3/common/constant"
        "dubbo.apache.org/dubbo-go/v3/protocol/grpc/internal/helloworld"
        "dubbo.apache.org/dubbo-go/v3/protocol/grpc/internal/routeguide"
 )
@@ -44,6 +45,7 @@ func TestUnaryClient(t *testing.T) {
 
        url, err := common.NewURL(helloworldURL)
        require.NoError(t, err)
+       url.SetAttribute(constant.RpcServiceKey, &helloworld.GrpcGreeterImpl{})
 
        cli, err := NewClient(url)
        require.NoError(t, err)
@@ -62,6 +64,7 @@ func TestStreamClient(t *testing.T) {
 
        url, err := common.NewURL(routeguideURL)
        require.NoError(t, err)
+       url.SetAttribute(constant.RpcServiceKey, 
&routeguide.RouteGuideClientImpl{})
 
        cli, err := NewClient(url)
        require.NoError(t, err)
diff --git a/protocol/grpc/grpc_invoker_test.go 
b/protocol/grpc/grpc_invoker_test.go
index cb961ebb6..b1cb637fa 100644
--- a/protocol/grpc/grpc_invoker_test.go
+++ b/protocol/grpc/grpc_invoker_test.go
@@ -30,6 +30,7 @@ import (
 
 import (
        "dubbo.apache.org/dubbo-go/v3/common"
+       "dubbo.apache.org/dubbo-go/v3/common/constant"
        "dubbo.apache.org/dubbo-go/v3/protocol/grpc/internal/helloworld"
        "dubbo.apache.org/dubbo-go/v3/protocol/grpc/internal/routeguide"
        "dubbo.apache.org/dubbo-go/v3/protocol/invocation"
@@ -57,10 +58,10 @@ func TestUnaryInvoke(t *testing.T) {
 
        url, err := common.NewURL(helloworldURL)
        require.NoError(t, err)
+       url.SetAttribute(constant.RpcServiceKey, &helloworld.GrpcGreeterImpl{})
 
        cli, err := NewClient(url)
        require.NoError(t, err)
-       cli.invoker = 
reflect.ValueOf(helloworld.NewGreeterClient(cli.ClientConn))
 
        var args []reflect.Value
        args = append(args, reflect.ValueOf(&helloworld.HelloRequest{Name: 
"request name"}))
@@ -86,10 +87,10 @@ func TestStreamInvoke(t *testing.T) {
 
        url, err := common.NewURL(routeguideURL)
        require.NoError(t, err)
+       url.SetAttribute(constant.RpcServiceKey, 
&routeguide.RouteGuideClientImpl{})
 
        cli, err := NewClient(url)
        require.NoError(t, err)
-       cli.invoker = 
reflect.ValueOf(routeguide.NewRouteGuideClient(cli.ClientConn))
 
        invoker := NewGrpcInvoker(url, cli)
 
diff --git a/protocol/grpc/grpc_protocol_test.go 
b/protocol/grpc/grpc_protocol_test.go
index 6a2e09002..93bd64ea1 100644
--- a/protocol/grpc/grpc_protocol_test.go
+++ b/protocol/grpc/grpc_protocol_test.go
@@ -28,6 +28,7 @@ import (
 
 import (
        "dubbo.apache.org/dubbo-go/v3/common"
+       "dubbo.apache.org/dubbo-go/v3/common/constant"
        "dubbo.apache.org/dubbo-go/v3/protocol/grpc/internal/helloworld"
 )
 
@@ -39,6 +40,7 @@ func TestGrpcProtocolRefer(t *testing.T) {
 
        url, err := common.NewURL(helloworldURL)
        require.NoError(t, err)
+       url.SetAttribute(constant.RpcServiceKey, &helloworld.GrpcGreeterImpl{})
 
        proto := GetProtocol()
        invoker := proto.Refer(url)
diff --git a/protocol/grpc/server.go b/protocol/grpc/server.go
index 635de4e1f..354a732d7 100644
--- a/protocol/grpc/server.go
+++ b/protocol/grpc/server.go
@@ -18,7 +18,6 @@
 package grpc
 
 import (
-       "crypto/tls"
        "fmt"
        "net"
        "sync"
@@ -41,10 +40,8 @@ import (
 )
 
 import (
-       "dubbo.apache.org/dubbo-go/v3"
        "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"
        dubbotls "dubbo.apache.org/dubbo-go/v3/tls"
@@ -86,6 +83,12 @@ func (s *Server) Start(url *common.URL) {
        if err != nil {
                panic(err)
        }
+       success := false
+       defer func() {
+               if !success {
+                       _ = lis.Close()
+               }
+       }()
 
        maxServerRecvMsgSize := constant.DefaultMaxServerRecvMsgSize
        if recvMsgSize, convertErr := 
humanize.ParseBytes(url.GetParam(constant.MaxServerRecvMsgSize, "")); 
convertErr == nil && recvMsgSize != 0 {
@@ -107,23 +110,9 @@ func (s *Server) Start(url *common.URL) {
                grpc.MaxSendMsgSize(maxServerSendMsgSize),
        )
 
-       // TODO: remove config TLSConfig
-       // delete this branch
-       tlsConfig := config.GetRootConfig().TLSConfig
-       if tlsConfig != nil {
-               var cfg *tls.Config
-               cfg, err = config.GetServerTlsConfig(&config.TLSConfig{
-                       CACertFile:    tlsConfig.CACertFile,
-                       TLSCertFile:   tlsConfig.TLSCertFile,
-                       TLSKeyFile:    tlsConfig.TLSKeyFile,
-                       TLSServerName: tlsConfig.TLSServerName,
-               })
-               if err != nil {
-                       return
-               }
-               logger.Infof("gRPC Server initialized the TLSConfig 
configuration")
-               serverOpts = append(serverOpts, 
grpc.Creds(credentials.NewTLS(cfg)))
-       } else if tlsConfRaw, ok := url.GetAttribute(constant.TLSConfigKey); ok 
{
+       var transportCreds credentials.TransportCredentials
+       transportCreds = insecure.NewCredentials()
+       if tlsConfRaw, ok := url.GetAttribute(constant.TLSConfigKey); ok {
                // use global TLSConfig handle tls
                tlsConf, ok := tlsConfRaw.(*global.TLSConfig)
                if !ok {
@@ -137,18 +126,15 @@ func (s *Server) Start(url *common.URL) {
                        }
                        if cfg != nil {
                                logger.Infof("gRPC Server initialized the 
TLSConfig configuration")
-                               serverOpts = append(serverOpts, 
grpc.Creds(credentials.NewTLS(cfg)))
+                               transportCreds = credentials.NewTLS(cfg)
                        }
-               } else {
-                       serverOpts = append(serverOpts, 
grpc.Creds(insecure.NewCredentials()))
                }
-       } else {
-               // TODO: remove this else
-               serverOpts = append(serverOpts, 
grpc.Creds(insecure.NewCredentials()))
        }
+       serverOpts = append(serverOpts, grpc.Creds(transportCreds))
 
        server := grpc.NewServer(serverOpts...)
        s.grpcServer = server
+       success = true
 
        go func() {
                providerServices := getProviderServices(url)
@@ -166,13 +152,8 @@ func (s *Server) Start(url *common.URL) {
        }()
 }
 
-// getProviderServices retrieves provider services from config or URL 
attributes
+// getProviderServices retrieves provider services from URL attributes.
 func getProviderServices(url *common.URL) map[string]*global.ServiceConfig {
-       providerServices := config.GetProviderConfig().Services
-       if len(providerServices) > 0 {
-               return convertServiceMap(providerServices)
-       }
-       // TODO #2741 old config compatibility
        if providerConfRaw, ok := url.GetAttribute(constant.ProviderConfigKey); 
ok {
                if providerConf, ok := 
providerConfRaw.(*global.ProviderConfig); ok && providerConf != nil {
                        return providerConf.Services
@@ -193,16 +174,7 @@ func getSyncMapLen(m *sync.Map) int {
        return length
 }
 
-func convertServiceMap(providerServices map[string]*config.ServiceConfig) 
map[string]*global.ServiceConfig {
-       result := make(map[string]*global.ServiceConfig)
-       for k, v := range providerServices {
-               result[k] = dubbo.CompatGlobalServiceConfig(v)
-       }
-       return result
-}
-
 // waitGrpcExporter wait until len(providerServices) = len(ExporterMap)
-// TODO #2741 old config compatibility
 func waitGrpcExporter(providerServices map[string]*global.ServiceConfig) {
        t := time.NewTicker(50 * time.Millisecond)
        defer t.Stop()
@@ -224,16 +196,8 @@ func waitGrpcExporter(providerServices 
map[string]*global.ServiceConfig) {
 }
 
 // registerService SetProxyImpl invoker and grpc service
-// TODO #2741 old config compatibility
 func registerService(providerServices map[string]*global.ServiceConfig, server 
*grpc.Server) {
-       for key, providerService := range providerServices {
-
-               //TODO: Temporary compatibility with old APIs, can be removed 
later
-               service := config.GetProviderService(key)
-               ds, ok := service.(DubboGrpcService)
-               if !ok {
-                       panic("illegal service type registered")
-               }
+       for _, providerService := range providerServices {
                serviceKey := common.ServiceKey(providerService.Interface, 
providerService.Group, providerService.Version)
                exporter, _ := grpcProtocol.ExporterMap().Load(serviceKey)
                if exporter == nil {
@@ -243,9 +207,17 @@ func registerService(providerServices 
map[string]*global.ServiceConfig, server *
                if invoker == nil {
                        panic(fmt.Sprintf("no invoker found for servicekey: 
%v", serviceKey))
                }
+               service, ok := 
invoker.GetURL().GetAttribute(constant.RpcServiceKey)
+               if !ok {
+                       panic(fmt.Sprintf("no rpc service found in url 
attribute %s for servicekey: %v", constant.RpcServiceKey, serviceKey))
+               }
+               ds, ok := service.(DubboGrpcService)
+               if !ok {
+                       panic("illegal service type registered")
+               }
 
                ds.SetProxyImpl(invoker)
-               server.RegisterService(ds.ServiceDesc(), service)
+               server.RegisterService(ds.ServiceDesc(), ds)
        }
 }
 

Reply via email to