Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[3.1] fix: metadata port reuse #2548

Merged
merged 2 commits into from
Dec 28, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions config/application_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
19 changes: 18 additions & 1 deletion metadata/service/exporter/configurable/exporter.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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).
Expand All @@ -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 does not support triple protocol,"+
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The warning message would better be "[Metadata Service] Dubbo-go %s version's MetadataService only support dubbo protocol, ". Because it might be other protocols beyond dubbo and triple.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, that's better

"MetadataService will use random port",
dubbo.Version)
}
}
return port
}

// Unexport will unexport the metadataService
func (exporter *MetadataServiceExporter) Unexport() {
if exporter.IsExported() {
Expand Down
21 changes: 21 additions & 0 deletions version.go
Original file line number Diff line number Diff line change
@@ -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"
Loading