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

fix: nacos servicediscovery group、namespace #1581

Merged
merged 2 commits into from
Nov 11, 2021
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
2 changes: 0 additions & 2 deletions common/constant/key.go
Original file line number Diff line number Diff line change
Expand Up @@ -138,8 +138,6 @@ const (
ServiceRegistryProtocol = "service-discovery-registry"
RegistryRoleKey = "registry.role"
RegistryDefaultKey = "registry.default"
RegistryUsernameKey = "registry.username"
RegistryPasswordKey = "registry.password"
RegistryAccessKey = "registry.accesskey"
RegistrySecretKey = "registry.secretkey"
RegistryTimeoutKey = "registry.timeout"
Expand Down
4 changes: 4 additions & 0 deletions config/config_center_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,8 @@ type CenterConfig struct {
Namespace string `yaml:"namespace" json:"namespace,omitempty"`
AppID string `default:"dubbo" yaml:"app-id" json:"app-id,omitempty"`
Timeout string `default:"10s" yaml:"timeout" json:"timeout,omitempty"`
AccessKey string `yaml:"access-key" json:"access-key,omitempty" property:"access-key"`
SecretKey string `yaml:"secret-key" json:"secret-key,omitempty" property:"secret-key"`
LaurenceLiZhixin marked this conversation as resolved.
Show resolved Hide resolved
Params map[string]string `yaml:"params" json:"parameters,omitempty"`
}

Expand Down Expand Up @@ -94,6 +96,8 @@ func (c *CenterConfig) GetUrlMap() url.Values {
urlMap.Set(constant.ConfigClusterKey, c.Cluster)
urlMap.Set(constant.ConfigAppIDKey, c.AppID)
urlMap.Set(constant.ConfigUsernameKey, c.Username)
urlMap.Set(constant.ConfigAccessKey, c.AccessKey)
urlMap.Set(constant.ConfigSecretKey, c.SecretKey)
urlMap.Set(constant.ConfigPasswordKey, c.Password)
urlMap.Set(constant.ConfigTimeoutKey, c.Timeout)

Expand Down
5 changes: 5 additions & 0 deletions config/registry_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ type RegistryConfig struct {
Group string `yaml:"group" json:"group,omitempty" property:"group"`
Namespace string `yaml:"namespace" json:"namespace,omitempty" property:"namespace"`
TTL string `default:"10s" yaml:"ttl" json:"ttl,omitempty" property:"ttl"` // unit: minute
AccessKey string `yaml:"access-key" json:"access-key,omitempty" property:"access-key"`
SecretKey string `yaml:"secret-key" json:"secret-key,omitempty" property:"secret-key"`
// for registry
Address string `validate:"required" yaml:"address" json:"address,omitempty" property:"address"`
Username string `yaml:"username" json:"username,omitempty" property:"username"`
Expand Down Expand Up @@ -130,6 +132,9 @@ func (c *RegistryConfig) toURL(roleType common.RoleType) (*common.URL, error) {
common.WithParamsValue(constant.RegistrySimplifiedKey, strconv.FormatBool(c.Simplified)),
common.WithParamsValue(constant.RegistryKey, c.Protocol),
common.WithParamsValue(constant.RegistryNamespaceKey, c.Namespace),
common.WithParamsValue(constant.RegistryAccessKey, c.AccessKey),
common.WithParamsValue(constant.RegistrySecretKey, c.SecretKey),
common.WithParamsValue(constant.RegistrySecretKey, c.SecretKey),
common.WithUsername(c.Username),
common.WithPassword(c.Password),
common.WithLocation(c.Address),
Expand Down
3 changes: 2 additions & 1 deletion registry/nacos/registry.go
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,8 @@ func newNacosRegistry(url *common.URL) (registry.Registry, error) {
logger.Infof("[Nacos Registry] New nacos registry with url = %+v", url.ToMap())
// key transfer: registry -> nacos
url.SetParam(constant.NacosNamespaceID, url.GetParam(constant.RegistryNamespaceKey, ""))
url.SetParam(constant.NacosUsername, url.GetParam(constant.RegistryUsernameKey, ""))
url.SetParam(constant.NacosUsername, url.Username)
url.SetParam(constant.NacosPassword, url.Password)
url.SetParam(constant.NacosAccessKey, url.GetParam(constant.RegistryAccessKey, ""))
url.SetParam(constant.NacosSecretKey, url.GetParam(constant.RegistrySecretKey, ""))
url.SetParam(constant.TimeoutKey, url.GetParam(constant.RegistryTimeoutKey, ""))
Expand Down
14 changes: 8 additions & 6 deletions registry/nacos/service_discovery.go
Original file line number Diff line number Diff line change
Expand Up @@ -332,21 +332,23 @@ func newNacosServiceDiscovery(url *common.URL) (registry.ServiceDiscovery, error
discoveryURL := common.NewURLWithOptions(
common.WithParams(url.GetParams()),
common.WithParamsValue(constant.TimeoutKey, url.GetParam(constant.RegistryTimeoutKey, constant.DefaultRegTimeout)),
common.WithParamsValue(constant.RegistryUsernameKey, url.GetParam(constant.RegistryUsernameKey, "")),
common.WithParamsValue(constant.RegistryPasswordKey, url.GetParam(constant.RegistryPasswordKey, "")),
common.WithParamsValue(constant.NacosGroupKey, url.GetParam(constant.RegistryGroupKey, defaultGroup)),
common.WithParamsValue(constant.NacosUsername, url.Username),
common.WithParamsValue(constant.NacosPassword, url.Password),
common.WithParamsValue(constant.NacosAccessKey, url.GetParam(constant.RegistryAccessKey, "")),
common.WithParamsValue(constant.NacosSecretKey, url.GetParam(constant.RegistrySecretKey, "")),
common.WithParamsValue(constant.NacosNamespaceID, url.GetParam(constant.RegistryNamespaceKey, "")))
discoveryURL.Location = url.Location
discoveryURL.Username = url.Username
discoveryURL.Password = url.Password
client, err := nacos.NewNacosClientByURL(discoveryURL)
if err != nil {
return nil, perrors.WithMessage(err, "create nacos namingClient failed.")
}

descriptor := fmt.Sprintf("nacos-service-discovery[%s]", discoveryURL.Location)

group := discoveryURL.Group()
if len(group) == 0 {
group = defaultGroup
}
group := url.GetParam(constant.RegistryGroupKey, defaultGroup)
newInstance := &nacosServiceDiscovery{
group: group,
namingClient: client,
Expand Down