This is an automated email from the ASF dual-hosted git repository.

baerwang pushed a commit to branch release-3.1
in repository https://gitbox.apache.org/repos/asf/dubbo-go.git


The following commit(s) were added to refs/heads/release-3.1 by this push:
     new 796f90891 fix: metadata port reuse (#2548)
796f90891 is described below

commit 796f90891929c0df841e49de39667f31e705e674
Author: finalt <[email protected]>
AuthorDate: Thu Dec 28 20:04:08 2023 +0800

    fix: metadata port reuse (#2548)
---
 config/application_config.go                       |  5 +++--
 metadata/service/exporter/configurable/exporter.go | 19 ++++++++++++++++++-
 version.go                                         | 21 +++++++++++++++++++++
 3 files changed, 42 insertions(+), 3 deletions(-)

diff --git a/config/application_config.go b/config/application_config.go
index 60ea32f1f..42dfa886b 100644
--- a/config/application_config.go
+++ b/config/application_config.go
@@ -37,8 +37,9 @@ type ApplicationConfig struct {
        Owner        string `default:"dubbo-go" yaml:"owner" 
json:"owner,omitempty" property:"owner"`
        Environment  string `yaml:"environment" json:"environment,omitempty" 
property:"environment"`
        // the metadata type. remote or local
-       MetadataType string `default:"local" yaml:"metadata-type" 
json:"metadataType,omitempty" property:"metadataType"`
-       Tag          string `yaml:"tag" json:"tag,omitempty" property:"tag"`
+       MetadataType        string `default:"local" yaml:"metadata-type" 
json:"metadataType,omitempty" property:"metadataType"`
+       Tag                 string `yaml:"tag" json:"tag,omitempty" 
property:"tag"`
+       MetadataServicePort string `yaml:"metadata-service-port" 
json:"metadata-service-port,omitempty" property:"metadata-service-port"`
 }
 
 // Prefix dubbo.application
diff --git a/metadata/service/exporter/configurable/exporter.go 
b/metadata/service/exporter/configurable/exporter.go
index b8e17422e..f09d1da09 100644
--- a/metadata/service/exporter/configurable/exporter.go
+++ b/metadata/service/exporter/configurable/exporter.go
@@ -26,6 +26,7 @@ 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/common/extension"
@@ -65,7 +66,7 @@ func (exporter *MetadataServiceExporter) Export(url 
*common.URL) error {
                        SetServiceID(constant.SimpleMetadataServiceName).
                        SetProtocolIDs(constant.DefaultProtocol).
                        AddRCProtocol(constant.DefaultProtocol, 
config.NewProtocolConfigBuilder().
-                               SetName(constant.DefaultProtocol).
+                               
SetName(constant.DefaultProtocol).SetPort(getMetadataPort()).
                                Build()).
                        SetRegistryIDs("N/A").
                        SetInterface(constant.MetadataServiceName).
@@ -84,6 +85,22 @@ func (exporter *MetadataServiceExporter) Export(url 
*common.URL) error {
        return nil
 }
 
+func getMetadataPort() string {
+       rootConfig := config.GetRootConfig()
+       port := rootConfig.Application.MetadataServicePort
+       if port == "" {
+               protocolConfig, ok := 
rootConfig.Protocols[constant.DefaultProtocol]
+               if ok {
+                       port = protocolConfig.Port
+               } else {
+                       logger.Warnf("[Metadata Service] Dubbo-go %s version's 
MetadataService only support dubbo protocol,"+
+                               "MetadataService will use random port",
+                               dubbo.Version)
+               }
+       }
+       return port
+}
+
 // Unexport will unexport the metadataService
 func (exporter *MetadataServiceExporter) Unexport() {
        if exporter.IsExported() {
diff --git a/version.go b/version.go
new file mode 100644
index 000000000..a6f6dfdfc
--- /dev/null
+++ b/version.go
@@ -0,0 +1,21 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package dubbo
+
+// dubbo-go version
+const Version = "3.1.1"

Reply via email to