Skip to content

Commit

Permalink
refactor:remove providers: prefix when use polaris
Browse files Browse the repository at this point in the history
  • Loading branch information
chuntaojun committed Mar 29, 2023
1 parent 4240c12 commit 5a76a5e
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 36 deletions.
2 changes: 1 addition & 1 deletion cluster/router/polaris/router.go
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ func getService(url *common.URL) string {
}
}

service := "providers:" + url.Service()
service := url.Interface()
if applicationMode {
service = config.GetApplicationConfig().Name
}
Expand Down
2 changes: 1 addition & 1 deletion filter/polaris/limit/limiter.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ func (pl *polarisTpsLimiter) buildQuotaRequest(url *common.URL, invoaction proto
}
}

svc := "providers:" + url.Service()
svc := url.Interface()
method := invoaction.MethodName()
if applicationMode {
svc = config.GetApplicationConfig().Name
Expand Down
16 changes: 8 additions & 8 deletions registry/polaris/registry.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ func (pr *polarisRegistry) Register(url *common.URL) error {
return nil
}

serviceName := getServiceName(url)
serviceName := url.Interface()
request := createRegisterParam(url, serviceName)
request.Namespace = pr.namespace
resp, err := pr.provider.RegisterInstance(request)
Expand All @@ -118,11 +118,11 @@ func (pr *polarisRegistry) Register(url *common.URL) error {
}

// UnRegister returns nil if unregister successfully. If not, returns an error.
func (pr *polarisRegistry) UnRegister(conf *common.URL) error {
request := createDeregisterParam(conf, getServiceName(conf))
func (pr *polarisRegistry) UnRegister(url *common.URL) error {
request := createDeregisterParam(url, url.Interface())
request.Namespace = pr.namespace
if err := pr.provider.Deregister(request); err != nil {
return perrors.WithMessagef(err, "register(conf:%+v)", conf)
return perrors.WithMessagef(err, "register(conf:%+v)", url)
}
return nil
}
Expand All @@ -138,7 +138,7 @@ func (pr *polarisRegistry) Subscribe(url *common.URL, notifyListener registry.No
defer timer.Stop()

for {
serviceName := getSubscribeName(url)
serviceName := url.Interface()
watcher, err := pr.createPolarisWatcher(serviceName)
if err != nil {
logger.Warnf("getwatcher() = err:%v", perrors.WithStack(err))
Expand Down Expand Up @@ -177,9 +177,9 @@ func (pr *polarisRegistry) UnSubscribe(url *common.URL, notifyListener registry.

// LoadSubscribeInstances load subscribe instance
func (pr *polarisRegistry) LoadSubscribeInstances(url *common.URL, notify registry.NotifyListener) error {
serviceName := getSubscribeName(url)
resp, err := pr.consumer.GetAllInstances(&api.GetAllInstancesRequest{
GetAllInstancesRequest: model.GetAllInstancesRequest{
serviceName := url.Interface()
resp, err := pr.consumer.GetInstances(&api.GetInstancesRequest{
GetInstancesRequest: model.GetInstancesRequest{
Service: serviceName,
Namespace: pr.namespace,
},
Expand Down
26 changes: 0 additions & 26 deletions registry/polaris/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,8 @@
package polaris

import (
"bytes"
"fmt"
"strconv"
"strings"
)

import (
Expand All @@ -45,27 +43,3 @@ func getCategory(url *common.URL) string {
category := common.DubboNodes[role]
return category
}

// just copy from dubbo-go for nacos
func getServiceName(url *common.URL) string {
var buffer bytes.Buffer
appendParam(&buffer, url, constant.InterfaceKey)
return buffer.String()
}

func getSubscribeName(url *common.URL) string {
var buffer bytes.Buffer

buffer.Write([]byte(common.DubboNodes[common.PROVIDER]))
appendParam(&buffer, url, constant.InterfaceKey)
return buffer.String()
}

// just copy from dubbo-go for nacos
func appendParam(target *bytes.Buffer, url *common.URL, key string) {
value := url.GetParam(key, "")
target.Write([]byte(constant.PolarisServiceNameSeparator))
if strings.TrimSpace(value) != "" {
target.Write([]byte(value))
}
}

0 comments on commit 5a76a5e

Please sign in to comment.