Skip to content
Snippets Groups Projects
Commit 88e20e91 authored by 邹毅贤's avatar 邹毅贤
Browse files

merge 1.4

parent 64153a64
No related branches found
No related tags found
No related merge requests found
......@@ -25,7 +25,8 @@ import (
)
import (
"github.com/pkg/errors"
gxset "github.com/dubbogo/gost/container/set"
perrors "github.com/pkg/errors"
"github.com/zouyx/agollo/v3"
agolloConstant "github.com/zouyx/agollo/v3/constant"
"github.com/zouyx/agollo/v3/env/config"
......
......@@ -176,7 +176,7 @@ func initNacosConfigClient(nacosAddrs []string, timeout time.Duration, url commo
Endpoint: url.GetParam(constant.NACOS_ENDPOINT, ""),
Username: url.GetParam(constant.NACOS_USERNAME, ""),
Password: url.GetParam(constant.NACOS_PASSWORD, ""),
NamespaceId: url.GetParam(constant.NACOS_NAMESPACEID, ""),
NamespaceId: url.GetParam(constant.NACOS_NAMESPACE_ID, ""),
},
})
}
......
module github.com/apache/dubbo-go
require (
cloud.google.com/go v0.39.0 // indirect
github.com/Microsoft/go-winio v0.4.13 // indirect
github.com/NYTimes/gziphandler v1.1.1 // indirect
github.com/Workiva/go-datastructures v1.0.50
......@@ -46,14 +45,12 @@ require (
github.com/prometheus/client_golang v1.1.0
github.com/satori/go.uuid v1.2.1-0.20181028125025-b2ce2384e17b
github.com/shirou/gopsutil v2.19.9+incompatible // indirect
github.com/smartystreets/goconvey v0.0.0-20190710185942-9d28bd7c0945 // indirect
github.com/stretchr/objx v0.2.0 // indirect
github.com/stretchr/testify v1.5.1
github.com/zouyx/agollo/v3 v3.4.4
go.etcd.io/bbolt v1.3.4 // indirect
go.uber.org/atomic v1.6.0
go.uber.org/zap v1.15.0
google.golang.org/genproto v0.0.0-20190801165951-fa694d86fc64 // indirect
google.golang.org/grpc v1.23.0
gopkg.in/yaml.v2 v2.2.8
k8s.io/api v0.16.9
......
......@@ -62,66 +62,6 @@ type nacosRegistry struct {
registryUrls []common.URL
}
func getNacosConfig(url *common.URL) (map[string]interface{}, error) {
if url == nil {
return nil, perrors.New("url is empty!")
}
if len(url.Location) == 0 {
return nil, perrors.New("url.location is empty!")
}
configMap := make(map[string]interface{}, 2)
addresses := strings.Split(url.Location, ",")
serverConfigs := make([]nacosConstant.ServerConfig, 0, len(addresses))
for _, addr := range addresses {
ip, portStr, err := net.SplitHostPort(addr)
if err != nil {
return nil, perrors.WithMessagef(err, "split [%s] ", addr)
}
port, _ := strconv.Atoi(portStr)
serverConfigs = append(serverConfigs, nacosConstant.ServerConfig{
IpAddr: ip,
Port: uint64(port),
})
}
configMap["serverConfigs"] = serverConfigs
var clientConfig nacosConstant.ClientConfig
timeout, err := time.ParseDuration(url.GetParam(constant.REGISTRY_TIMEOUT_KEY, constant.DEFAULT_REG_TIMEOUT))
if err != nil {
return nil, err
}
clientConfig.TimeoutMs = uint64(timeout.Seconds() * 1000)
clientConfig.ListenInterval = 2 * clientConfig.TimeoutMs
clientConfig.CacheDir = url.GetParam(constant.NACOS_CACHE_DIR_KEY, "")
clientConfig.LogDir = url.GetParam(constant.NACOS_LOG_DIR_KEY, "")
clientConfig.Endpoint = url.GetParam(constant.NACOS_ENDPOINT, "")
clientConfig.Username = url.GetParam(constant.NACOS_USERNAME, "")
clientConfig.Password = url.GetParam(constant.NACOS_PASSWORD, "")
clientConfig.NamespaceId = url.GetParam(constant.NACOS_NAMESPACEID, "")
clientConfig.NotLoadCacheAtStart = true
configMap["clientConfig"] = clientConfig
return configMap, nil
}
func newNacosRegistry(url *common.URL) (registry.Registry, error) {
nacosConfig, err := getNacosConfig(url)
if err != nil {
return nil, err
}
client, err := clients.CreateNamingClient(nacosConfig)
if err != nil {
return nil, err
}
registry := nacosRegistry{
URL: url,
namingClient: client,
registryUrls: []common.URL{},
}
return &registry, nil
}
func getCategory(url common.URL) string {
role, _ := strconv.Atoi(url.GetParam(constant.ROLE_KEY, strconv.Itoa(constant.NACOS_DEFAULT_ROLETYPE)))
category := common.DubboNodes[role]
......@@ -178,22 +118,6 @@ func createRegisterParam(url common.URL, serviceName string) vo.RegisterInstance
return instance
}
func createDeregisterParam(url common.URL, serviceName string) vo.DeregisterInstanceParam {
if len(url.Ip) == 0 {
url.Ip = localIP
}
if len(url.Port) == 0 || url.Port == "0" {
url.Port = "80"
}
port, _ := strconv.Atoi(url.Port)
return vo.DeregisterInstanceParam{
Ip: url.Ip,
Port: uint64(port),
ServiceName: serviceName,
Ephemeral: true,
}
}
// Register will register the service @url to its nacos registry center
func (nr *nacosRegistry) Register(url common.URL) error {
serviceName := getServiceName(url)
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment