Merge branch 'apache:3.0' into 3.0
diff --git a/.gitignore b/.gitignore
index 6605c27..01a7dbf 100644
--- a/.gitignore
+++ b/.gitignore
@@ -20,6 +20,7 @@
classes
# go mod, go test
+.go-version
vendor/
logs/
.vscode/
diff --git a/config/graceful_shutdown.go b/config/graceful_shutdown.go
index 6b81c5d..54ed81b 100644
--- a/config/graceful_shutdown.go
+++ b/config/graceful_shutdown.go
@@ -71,7 +71,7 @@
filter.Set(constant.GracefulShutdownFilterShutdownConfig, GetShutDown())
}
- if GetShutDown().InternalSignal {
+ if GetShutDown().GetInternalSignal() {
signals := make(chan os.Signal, 1)
signal.Notify(signals, ShutdownSignals...)
diff --git a/config/graceful_shutdown_config.go b/config/graceful_shutdown_config.go
index d0779a8..044087b 100644
--- a/config/graceful_shutdown_config.go
+++ b/config/graceful_shutdown_config.go
@@ -66,7 +66,7 @@
// when we try to shutdown the applicationConfig, we will reject the new requests. In most cases, you don't need to configure this.
RejectRequestHandler string `yaml:"reject-handler" json:"reject-handler,omitempty" property:"reject_handler"`
// internal listen kill signal,the default is true.
- InternalSignal bool `default:"true" yaml:"internal-signal" json:"internal.signal,omitempty" property:"internal.signal"`
+ InternalSignal *bool `default:"true" yaml:"internal-signal" json:"internal.signal,omitempty" property:"internal.signal"`
// offline request window length
OfflineRequestWindowTimeout string `yaml:"offline-request-window-timeout" json:"offlineRequestWindowTimeout,omitempty" property:"offlineRequestWindowTimeout"`
// true -> new request will be rejected.
@@ -124,6 +124,13 @@
return result
}
+func (config *ShutdownConfig) GetInternalSignal() bool {
+ if config.InternalSignal == nil {
+ return false
+ }
+ return *config.InternalSignal
+}
+
func (config *ShutdownConfig) Init() error {
return defaults.Set(config)
}
@@ -157,12 +164,12 @@
}
func (scb *ShutdownConfigBuilder) SetInternalSignal(internalSignal bool) *ShutdownConfigBuilder {
- scb.shutdownConfig.InternalSignal = internalSignal
+ scb.shutdownConfig.InternalSignal = &internalSignal
return scb
}
func (scb *ShutdownConfigBuilder) Build() *ShutdownConfig {
- defaults.Set(scb)
+ defaults.MustSet(scb.shutdownConfig)
return scb.shutdownConfig
}
diff --git a/config/graceful_shutdown_config_test.go b/config/graceful_shutdown_config_test.go
index c76098b..fe6890d 100644
--- a/config/graceful_shutdown_config_test.go
+++ b/config/graceful_shutdown_config_test.go
@@ -68,7 +68,7 @@
SetOfflineRequestWindowTimeout("13s").
SetRejectRequestHandler("handler").
SetRejectRequest(true).
- SetInternalSignal(true).
+ SetInternalSignal(false).
Build()
assert.Equal(t, config.Prefix(), constant.ShutdownConfigPrefix)
@@ -86,4 +86,18 @@
waitTime := config.GetConsumerUpdateWaitTime()
assert.Equal(t, waitTime, 3*time.Second)
+
+ assert.Equal(t, config.GetInternalSignal(), false)
+}
+
+func TestGetInternalSignal(t *testing.T) {
+ config := NewShutDownConfigBuilder().
+ SetTimeout("10s").
+ SetStepTimeout("15s").
+ SetOfflineRequestWindowTimeout("13s").
+ SetRejectRequestHandler("handler").
+ SetRejectRequest(true).
+ Build()
+
+ assert.Equal(t, config.GetInternalSignal(), true)
}
diff --git a/go.mod b/go.mod
index ceb723c..48b8b7b 100644
--- a/go.mod
+++ b/go.mod
@@ -16,7 +16,7 @@
github.com/creasty/defaults v1.5.2
github.com/dubbogo/go-zookeeper v1.0.4-0.20211212162352-f9d2183d89d5
github.com/dubbogo/gost v1.12.6-0.20220719055648-01d5bc07b111
- github.com/dubbogo/grpc-go v1.42.9
+ github.com/dubbogo/grpc-go v1.42.10
github.com/dubbogo/triple v1.1.8
github.com/emicklei/go-restful/v3 v3.8.0
github.com/envoyproxy/go-control-plane v0.10.2-0.20220325020618-49ff273808a1
@@ -35,7 +35,7 @@
github.com/magiconair/properties v1.8.6
github.com/mitchellh/mapstructure v1.5.0
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd
- github.com/nacos-group/nacos-sdk-go v1.1.1
+ github.com/nacos-group/nacos-sdk-go v1.1.2
github.com/natefinch/lumberjack v2.0.0+incompatible
github.com/opentracing/opentracing-go v1.2.0
github.com/pkg/errors v0.9.1
@@ -45,8 +45,8 @@
github.com/stretchr/testify v1.8.0
go.etcd.io/etcd/api/v3 v3.5.4
go.etcd.io/etcd/client/v3 v3.5.4
- go.opentelemetry.io/otel v1.8.0
- go.opentelemetry.io/otel/trace v1.8.0
+ go.opentelemetry.io/otel v1.9.0
+ go.opentelemetry.io/otel/trace v1.9.0
go.uber.org/atomic v1.9.0
go.uber.org/zap v1.21.0
google.golang.org/genproto v0.0.0-20211104193956-4c6863e31247
diff --git a/go.sum b/go.sum
index 874cd6b..a333d6e 100644
--- a/go.sum
+++ b/go.sum
@@ -175,8 +175,9 @@
github.com/dubbogo/gost v1.11.23/go.mod h1:PhJ8+qZJx+Txjx1KthNPuVkCvUca0jRLgKWj/noGgeI=
github.com/dubbogo/gost v1.12.6-0.20220719055648-01d5bc07b111 h1:ydfcIHE0slI/R1plWVKaJWpgwo60EuZ5MQyQ3ZiOITQ=
github.com/dubbogo/gost v1.12.6-0.20220719055648-01d5bc07b111/go.mod h1:f0bcP1xpBUdDgiNjNYKF6F3qlA+RFKs0k980FhoEn/g=
-github.com/dubbogo/grpc-go v1.42.9 h1:nTuglkH9rTJzQfardU4b0OJ0Imd2169dMNLBTNhTdlc=
github.com/dubbogo/grpc-go v1.42.9/go.mod h1:F1T9hnUvYGW4JLK1QNriavpOkhusU677ovPzLkk6zHM=
+github.com/dubbogo/grpc-go v1.42.10 h1:CoyCdtqKJEar/3rPa6peZbDqYZ/mVsCqAxB6TfTSkhQ=
+github.com/dubbogo/grpc-go v1.42.10/go.mod h1:JMkPt1mIHL96GAFeYsMoMjew6f1ROKycikGzZQH1s5U=
github.com/dubbogo/jsonparser v1.0.1/go.mod h1:tYAtpctvSP/tWw4MeelsowSPgXQRVHHWbqL6ynps8jU=
github.com/dubbogo/net v0.0.4/go.mod h1:1CGOnM7X3he+qgGNqjeADuE5vKZQx/eMSeUkpU3ujIc=
github.com/dubbogo/triple v1.0.9/go.mod h1:1t9me4j4CTvNDcsMZy6/OGarbRyAUSY0tFXGXHCp7Iw=
@@ -200,6 +201,7 @@
github.com/envoyproxy/go-control-plane v0.9.9-0.20210512163311-63b5d3c536b0/go.mod h1:hliV/p42l8fGbc6Y9bQ70uLwIvmJyVE5k4iMKlh8wCQ=
github.com/envoyproxy/go-control-plane v0.9.10-0.20210907150352-cf90f659a021/go.mod h1:AFq3mo9L8Lqqiid3OhADV3RfLJnjiw63cSpi+fDTRC0=
github.com/envoyproxy/go-control-plane v0.10.0/go.mod h1:AY7fTTXNdv/aJ2O5jwpxAPOWUZ7hQAEvzN5Pf27BkQQ=
+github.com/envoyproxy/go-control-plane v0.10.1/go.mod h1:AY7fTTXNdv/aJ2O5jwpxAPOWUZ7hQAEvzN5Pf27BkQQ=
github.com/envoyproxy/go-control-plane v0.10.2-0.20220325020618-49ff273808a1 h1:xvqufLtNVwAhN8NMyWklVgxnWohi+wtMGQMhtxexlm0=
github.com/envoyproxy/go-control-plane v0.10.2-0.20220325020618-49ff273808a1/go.mod h1:KJwIaB5Mv44NWtYuAOFCVOjcI94vtpEz2JU/D2v6IjE=
github.com/envoyproxy/protoc-gen-validate v0.1.0 h1:EQciDnbrYxy13PgWoY8AqoxGiPrpgBZ1R8UNe3ddc+A=
@@ -560,8 +562,8 @@
github.com/mwitkow/go-conntrack v0.0.0-20161129095857-cc309e4a2223/go.mod h1:qRWi+5nqEBWmkhHvq77mSJWrCKwh8bxhgT7d/eI7P4U=
github.com/mwitkow/go-conntrack v0.0.0-20190716064945-2f068394615f/go.mod h1:qRWi+5nqEBWmkhHvq77mSJWrCKwh8bxhgT7d/eI7P4U=
github.com/nacos-group/nacos-sdk-go v1.0.8/go.mod h1:hlAPn3UdzlxIlSILAyOXKxjFSvDJ9oLzTJ9hLAK1KzA=
-github.com/nacos-group/nacos-sdk-go v1.1.1 h1:beczWcOoTaVBMgCgikqvZflrN5Xbw7pWAWpxl+VJGIA=
-github.com/nacos-group/nacos-sdk-go v1.1.1/go.mod h1:UHOtQNQY/qpk2dhg6gDq8u5+/CEIc3+lWmrmxEzX0/g=
+github.com/nacos-group/nacos-sdk-go v1.1.2 h1:lWTpf5SXLetQetS7p31eGic/ncqsnn0Zbau1i3eC25Y=
+github.com/nacos-group/nacos-sdk-go v1.1.2/go.mod h1:I8Vj4M8ZLpBk7EY2A8RXQE1SbfCA7b56TJBPIFTrUYE=
github.com/natefinch/lumberjack v2.0.0+incompatible h1:4QJd3OLAMgj7ph+yZTuX13Ld4UpgHp07nNdFX7mqFfM=
github.com/natefinch/lumberjack v2.0.0+incompatible/go.mod h1:Wi9p2TTF5DG5oU+6YfsmYQpsTIOm0B1VNzQg9Mw6nPk=
github.com/nats-io/jwt v0.3.0/go.mod h1:fRYCDE99xlTsqUzISS1Bi75UBJ6ljOJQOAAu5VglpSg=
@@ -689,8 +691,9 @@
github.com/sirupsen/logrus v1.2.0/go.mod h1:LxeOpSwHxABJmUn/MG1IvRgCAasNZTLOkJPxbbu5VWo=
github.com/sirupsen/logrus v1.4.2/go.mod h1:tLMulIdttU9McNUspp0xgXVQah82FyeX6MwdIuYE2rE=
github.com/sirupsen/logrus v1.6.0/go.mod h1:7uNnSEd1DgxDLC74fIahvMZmmYsHGZGEOFrfsX/uA88=
-github.com/sirupsen/logrus v1.7.0 h1:ShrD1U9pZB12TX0cVy0DtePoCH97K8EtX+mg7ZARUtM=
github.com/sirupsen/logrus v1.7.0/go.mod h1:yWOB1SBYBC5VeMP7gHvWumXLIWorT60ONWic61uBYv0=
+github.com/sirupsen/logrus v1.8.1 h1:dJKuHgqk1NNQlqoA6BTlM1Wf9DOH3NBjQyu0h9+AZZE=
+github.com/sirupsen/logrus v1.8.1/go.mod h1:yWOB1SBYBC5VeMP7gHvWumXLIWorT60ONWic61uBYv0=
github.com/smartystreets/assertions v0.0.0-20180927180507-b2de0cb4f26d h1:zE9ykElWQ6/NYmHa3jpm/yHnI4xSofP+UP6SpjHcSeM=
github.com/smartystreets/assertions v0.0.0-20180927180507-b2de0cb4f26d/go.mod h1:OnSkiWE9lh6wB0YB77sQom3nweQdgAjqCqsofrRNTgc=
github.com/smartystreets/goconvey v0.0.0-20190330032615-68dc04aab96a/go.mod h1:syvi0/a8iFYH4r/RixwvyeAJjdLS9QV7WQ/tjFTllLA=
@@ -796,10 +799,10 @@
go.opencensus.io v0.22.4/go.mod h1:yxeiOL68Rb0Xd1ddK5vPZ/oVn4vY4Ynel7k9FzqtOIw=
go.opencensus.io v0.23.0 h1:gqCw0LfLxScz8irSi8exQc7fyQ0fKQU/qnC/X8+V/1M=
go.opencensus.io v0.23.0/go.mod h1:XItmlyltB5F7CS4xOC1DcqMoFqwtC6OG2xF7mCv7P7E=
-go.opentelemetry.io/otel v1.8.0 h1:zcvBFizPbpa1q7FehvFiHbQwGzmPILebO0tyqIR5Djg=
-go.opentelemetry.io/otel v1.8.0/go.mod h1:2pkj+iMj0o03Y+cW6/m8Y4WkRdYN3AvCXCnzRMp9yvM=
-go.opentelemetry.io/otel/trace v1.8.0 h1:cSy0DF9eGI5WIfNwZ1q2iUyGj00tGzP24dE1lOlHrfY=
-go.opentelemetry.io/otel/trace v1.8.0/go.mod h1:0Bt3PXY8w+3pheS3hQUt+wow8b1ojPaTBoTCh2zIFI4=
+go.opentelemetry.io/otel v1.9.0 h1:8WZNQFIB2a71LnANS9JeyidJKKGOOremcUtb/OtHISw=
+go.opentelemetry.io/otel v1.9.0/go.mod h1:np4EoPGzoPs3O67xUVNoPPcmSvsfOxNlNA4F4AC+0Eo=
+go.opentelemetry.io/otel/trace v1.9.0 h1:oZaCNJUjWcg60VXWee8lJKlqhPbXAPB51URuR47pQYc=
+go.opentelemetry.io/otel/trace v1.9.0/go.mod h1:2737Q0MuG8q1uILYm2YYVkAyLtOofiTNGg6VODnOiPo=
go.opentelemetry.io/proto/otlp v0.7.0/go.mod h1:PqfVotwruBrMGOCsRd/89rSnXhoiJIqeYNgFYFoEGnI=
go.uber.org/atomic v1.3.2/go.mod h1:gD2HeocX3+yG+ygLZcrzQJaqmWj9AIm7n08wl/qW/PE=
go.uber.org/atomic v1.4.0/go.mod h1:gD2HeocX3+yG+ygLZcrzQJaqmWj9AIm7n08wl/qW/PE=
diff --git a/metadata/definition/definition.go b/metadata/definition/definition.go
index f1241d1..2cb11e3 100644
--- a/metadata/definition/definition.go
+++ b/metadata/definition/definition.go
@@ -21,6 +21,7 @@
"bytes"
"encoding/json"
"fmt"
+ "sort"
"strings"
)
@@ -70,8 +71,8 @@
// FullServiceDefinition is the describer of service definition with parameters
type FullServiceDefinition struct {
+ Parameters map[string]string
ServiceDefinition
- Params map[string]string
}
// MethodDefinition is the describer of method definition
@@ -121,6 +122,56 @@
return sd
}
+// BuildFullDefinition can build service definition with full url parameters
+func BuildFullDefinition(service common.Service, url *common.URL) *FullServiceDefinition {
+ fsd := &FullServiceDefinition{}
+ sd := BuildServiceDefinition(service, url)
+ fsd.ServiceDefinition = *sd
+ fsd.Parameters = make(map[string]string)
+ for k, v := range url.GetParams() {
+ fsd.Parameters[k] = strings.Join(v, ",")
+ }
+ return fsd
+}
+
+// ToBytes convert ServiceDefinition to json string
+func (def *FullServiceDefinition) ToBytes() ([]byte, error) {
+ return json.Marshal(def)
+}
+
+// String will iterate all methods and parameters and convert them to json string
+func (def *FullServiceDefinition) String() string {
+ var methodStr strings.Builder
+ for _, m := range def.Methods {
+ var paramType strings.Builder
+ for _, p := range m.ParameterTypes {
+ paramType.WriteString(fmt.Sprintf("{type:%v}", p))
+ }
+ var param strings.Builder
+ for _, d := range m.Parameters {
+ param.WriteString(fmt.Sprintf("{id:%v,type:%v,builderName:%v}", d.ID, d.Type, d.TypeBuilderName))
+ }
+ methodStr.WriteString(fmt.Sprintf("{name:%v,parameterTypes:[%v],returnType:%v,params:[%v] }", m.Name, paramType.String(), m.ReturnType, param.String()))
+ }
+ var types strings.Builder
+ for _, d := range def.Types {
+ types.WriteString(fmt.Sprintf("{id:%v,type:%v,builderName:%v}", d.ID, d.Type, d.TypeBuilderName))
+ }
+
+ sortSlice := make([]string, 0)
+ var parameters strings.Builder
+ for k := range def.Parameters {
+ sortSlice = append(sortSlice, k)
+ }
+ sort.Slice(sortSlice, func(i, j int) bool { return sortSlice[i] < sortSlice[j] })
+ for _, k := range sortSlice {
+ parameters.WriteString(fmt.Sprintf("%v:%v,", k, def.Parameters[k]))
+ }
+
+ return fmt.Sprintf("{parameters:{%v}, canonicalName:%v, codeSource:%v, methods:[%v], types:[%v]}",
+ strings.TrimRight(parameters.String(), ","), def.CanonicalName, def.CodeSource, methodStr.String(), types.String())
+}
+
// ServiceDescriperBuild builds the service key, format is `group/serviceName:version` which be same as URL's service key
func ServiceDescriperBuild(serviceName string, group string, version string) string {
buf := &bytes.Buffer{}
diff --git a/metadata/definition/definition_test.go b/metadata/definition/definition_test.go
index 6989fb7..7515b09 100644
--- a/metadata/definition/definition_test.go
+++ b/metadata/definition/definition_test.go
@@ -48,4 +48,6 @@
service := common.ServiceMap.GetServiceByServiceKey(url.Protocol, url.ServiceKey())
sd := BuildServiceDefinition(*service, url)
assert.Equal(t, "{canonicalName:com.ikurento.user.UserProvider, codeSource:, methods:[{name:GetUser,parameterTypes:[{type:slice}],returnType:ptr,params:[] }], types:[]}", sd.String())
+ fsd := BuildFullDefinition(*service, url)
+ assert.Equal(t, "{parameters:{anyhost:true,application:BDTService,bean.name:UserProvider,category:providers,default.timeout:10000,dubbo:dubbo-provider-golang-1.0.0,environment:dev,group:group1,interface:com.ikurento.user.UserProvider,ip:192.168.56.1,methods:GetUser,module:dubbogo user-info server,org:ikurento.com,owner:ZX,pid:1447,revision:0.0.1,side:provider,timeout:3000,timestamp:1556509797245,version:0.0.1}, canonicalName:com.ikurento.user.UserProvider, codeSource:, methods:[{name:GetUser,parameterTypes:[{type:slice}],returnType:ptr,params:[] }], types:[]}", fsd.String())
}
diff --git a/metadata/service/local/service.go b/metadata/service/local/service.go
index 2b2e6ac..aeac070 100644
--- a/metadata/service/local/service.go
+++ b/metadata/service/local/service.go
@@ -202,7 +202,7 @@
isGeneric := url.GetParamBool(constant.GenericKey, false)
if len(interfaceName) > 0 && !isGeneric {
tmpService := common.ServiceMap.GetServiceByServiceKey(url.Protocol, url.ServiceKey())
- sd := definition.BuildServiceDefinition(*tmpService, url)
+ sd := definition.BuildFullDefinition(*tmpService, url)
data, err := sd.ToBytes()
if err != nil {
logger.Errorf("publishProvider getServiceDescriptor error. providerUrl:%v , error:%v ", url, err)
diff --git a/metadata/service/local/service_test.go b/metadata/service/local/service_test.go
index c3bcc50..031c8a5 100644
--- a/metadata/service/local/service_test.go
+++ b/metadata/service/local/service_test.go
@@ -99,7 +99,14 @@
assert.NoError(t, err)
err = mts.PublishServiceDefinition(u)
assert.NoError(t, err)
- expected := "{\"CanonicalName\":\"com.ikurento.user.UserProvider\",\"CodeSource\":\"\"," +
+ expected := "{\"Parameters\":{\"anyhost\":\"true\",\"application\":\"BDTService\"," +
+ "\"bean.name\":\"UserProvider\",\"category\":\"providers\",\"default.timeout\":\"10000\"," +
+ "\"dubbo\":\"dubbo-provider-golang-1.0.0\",\"environment\":\"dev\",\"group\":\"group1\"," +
+ "\"interface\":\"com.ikurento.user.UserProvider\",\"ip\":\"192.168.56.1\"," +
+ "\"methods\":\"GetUser\",\"module\":\"dubbogo user-info server\",\"org\":\"ikurento.com\"," +
+ "\"owner\":\"ZX\",\"pid\":\"1447\",\"revision\":\"0.0.1\",\"side\":\"provider\"," +
+ "\"timeout\":\"3000\",\"timestamp\":\"1556509797245\",\"version\":\"0.0.1\"}," +
+ "\"CanonicalName\":\"com.ikurento.user.UserProvider\",\"CodeSource\":\"\"," +
"\"Methods\":[{\"Name\":\"GetUser\",\"ParameterTypes\":[\"slice\"],\"ReturnType\":\"ptr\"," +
"\"Parameters\":null}],\"Types\":null}"
def1, err := mts.GetServiceDefinition(serviceName, group, version)
diff --git a/metadata/service/remote/service.go b/metadata/service/remote/service.go
index aaf6aae..9b2ba39 100644
--- a/metadata/service/remote/service.go
+++ b/metadata/service/remote/service.go
@@ -109,7 +109,7 @@
if common.RoleType(common.PROVIDER).Role() == url.GetParam(constant.SideKey, "") {
if len(interfaceName) > 0 && !isGeneric {
sv := common.ServiceMap.GetServiceByServiceKey(url.Protocol, url.ServiceKey())
- sd := definition.BuildServiceDefinition(*sv, url)
+ sd := definition.BuildFullDefinition(*sv, url)
id := &identifier.MetadataIdentifier{
BaseMetadataIdentifier: identifier.BaseMetadataIdentifier{
ServiceInterface: interfaceName,
diff --git a/metadata/service/remote/service_test.go b/metadata/service/remote/service_test.go
index ae1eeea..fa4a17e 100644
--- a/metadata/service/remote/service_test.go
+++ b/metadata/service/remote/service_test.go
@@ -146,9 +146,17 @@
err = mts.PublishServiceDefinition(u)
assert.NoError(t, err)
- expected := "{\"CanonicalName\":\"com.ikurento.user.UserProvider\",\"CodeSource\":\"\"," +
+ expected := "{\"Parameters\":{\"anyhost\":\"true\",\"application\":\"BDTService\"," +
+ "\"bean.name\":\"UserProvider\",\"category\":\"providers\",\"default.timeout\":\"10000\"," +
+ "\"dubbo\":\"dubbo-provider-golang-1.0.0\",\"environment\":\"dev\",\"group\":\"group1\"," +
+ "\"interface\":\"com.ikurento.user.UserProvider\",\"ip\":\"192.168.56.1\"," +
+ "\"methods\":\"GetUser\",\"module\":\"dubbogo user-info server\",\"org\":\"ikurento.com\"," +
+ "\"owner\":\"ZX\",\"pid\":\"1447\",\"revision\":\"0.0.1\",\"side\":\"provider\"," +
+ "\"timeout\":\"3000\",\"timestamp\":\"1556509797245\",\"version\":\"0.0.1\"}," +
+ "\"CanonicalName\":\"com.ikurento.user.UserProvider\",\"CodeSource\":\"\"," +
"\"Methods\":[{\"Name\":\"GetUser\",\"ParameterTypes\":[\"slice\"],\"ReturnType\":\"ptr\"," +
"\"Parameters\":null}],\"Types\":null}"
+
def1, _ := mts.GetServiceDefinition(serviceName, group, version)
assert.Equal(t, expected, def1)
serviceKey := definition.ServiceDescriperBuild(serviceName, group, version)
diff --git a/registry/polaris/core_test.go b/registry/polaris/core_test.go
index 0e806a3..463d88a 100644
--- a/registry/polaris/core_test.go
+++ b/registry/polaris/core_test.go
@@ -17,6 +17,10 @@
)
func TestPolarisServiceWatcher_AddSubscriber(t *testing.T) {
+ var (
+ newParam api.WatchServiceRequest
+ newConsumer api.ConsumerAPI
+ )
type fields struct {
consumer api.ConsumerAPI
subscribeParam *api.WatchServiceRequest
diff --git a/registry/polaris/registry.go b/registry/polaris/registry.go
index 210c0da..255acdb 100644
--- a/registry/polaris/registry.go
+++ b/registry/polaris/registry.go
@@ -150,8 +150,11 @@
// Subscribe returns nil if subscribing registry successfully. If not returns an error.
func (pr *polarisRegistry) Subscribe(url *common.URL, notifyListener registry.NotifyListener) error {
- var newParam api.WatchServiceRequest
- var newConsumer api.ConsumerAPI
+ var (
+ newParam api.WatchServiceRequest
+ newConsumer api.ConsumerAPI
+ )
+
role, _ := strconv.Atoi(url.GetParam(constant.RegistryRoleKey, ""))
if role != common.CONSUMER {
return nil