Skip to content

Commit 544036a

Browse files
authored
Merge pull request #1 from apache/develop
Update forks merge
2 parents 284aa48 + 84b38fe commit 544036a

File tree

81 files changed

+2567
-476
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

81 files changed

+2567
-476
lines changed

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ Apache License, Version 2.0
1616

1717
## Release note ##
1818

19-
[v1.4.0-rc1 - Mar 12, 2020](https://github.com/apache/dubbo-go/releases/tag/v1.4.0-rc1)
19+
[v1.4.0 - Mar 17, 2020](https://github.com/apache/dubbo-go/releases/tag/v1.4.0)
2020

2121
[v1.3.0 - Mar 1, 2020](https://github.com/apache/dubbo-go/releases/tag/v1.3.0)
2222

README_CN.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ Apache License, Version 2.0
1515

1616
## 发布日志 ##
1717

18-
[v1.4.0-rc1 - 2020年3月12日](https://github.com/apache/dubbo-go/releases/tag/v1.4.0-rc1)
18+
[v1.4.0 - 2020年3月17日](https://github.com/apache/dubbo-go/releases/tag/v1.4.0)
1919

2020
[v1.3.0 - 2020年3月1日](https://github.com/apache/dubbo-go/releases/tag/v1.3.0)
2121

common/constant/key.go

+26-2
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,7 @@ const (
131131
ProviderConfigPrefix = "dubbo.provider."
132132
ConsumerConfigPrefix = "dubbo.consumer."
133133
ShutdownConfigPrefix = "dubbo.shutdown."
134+
MetadataReportPrefix = "dubbo.metadata-report."
134135
RouterConfigPrefix = "dubbo.router."
135136
)
136137

@@ -179,6 +180,9 @@ const (
179180
// ForceUseTag is the tag in attachment
180181
ForceUseTag = "dubbo.force.tag"
181182
Tagkey = "dubbo.tag"
183+
184+
// Attachment key in context in invoker
185+
AttachmentKey = "attachment"
182186
)
183187

184188
const (
@@ -209,9 +213,23 @@ const (
209213
// consumer
210214
CONSUMER = "consumer"
211215
// key of access key id
212-
ACCESS_KEY_ID_KEY = "accessKeyId"
216+
ACCESS_KEY_ID_KEY = ".accessKeyId"
213217
// key of secret access key
214-
SECRET_ACCESS_KEY_KEY = "secretAccessKey"
218+
SECRET_ACCESS_KEY_KEY = ".secretAccessKey"
219+
)
220+
221+
// metadata report
222+
223+
const (
224+
METACONFIG_REMOTE = "remote"
225+
METACONFIG_LOCAL = "local"
226+
KEY_SEPARATOR = ":"
227+
DEFAULT_PATH_TAG = "metadata"
228+
KEY_REVISON_PREFIX = "revision"
229+
PATH_SEPARATOR = "/"
230+
231+
// metadata service
232+
METADATA_SERVICE_NAME = "org.apache.dubbo.metadata.MetadataService"
215233
)
216234

217235
// HealthCheck Router
@@ -235,3 +253,9 @@ const (
235253
// The default time window of circuit-tripped in millisecond if not specfied
236254
MAX_CIRCUIT_TRIPPED_TIMEOUT_IN_MS = 30000
237255
)
256+
257+
// service discovery
258+
259+
const (
260+
NACOS_GROUP = "nacos.group"
261+
)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one or more
3+
* contributor license agreements. See the NOTICE file distributed with
4+
* this work for additional information regarding copyright ownership.
5+
* The ASF licenses this file to You under the Apache License, Version 2.0
6+
* (the "License"); you may not use this file except in compliance with
7+
* the License. You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
18+
package extension
19+
20+
import (
21+
"github.com/apache/dubbo-go/metadata"
22+
)
23+
24+
var (
25+
metaDataReportFactories = make(map[string]func() metadata.MetadataReportFactory, 8)
26+
)
27+
28+
// SetMetadataReportFactory ...
29+
func SetMetadataReportFactory(name string, v func() metadata.MetadataReportFactory) {
30+
metaDataReportFactories[name] = v
31+
}
32+
33+
// GetMetadataReportFactory ...
34+
func GetMetadataReportFactory(name string) metadata.MetadataReportFactory {
35+
if metaDataReportFactories[name] == nil {
36+
panic("metadata report for " + name + " is not existing, make sure you have import the package.")
37+
}
38+
return metaDataReportFactories[name]()
39+
}
+41
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one or more
3+
* contributor license agreements. See the NOTICE file distributed with
4+
* this work for additional information regarding copyright ownership.
5+
* The ASF licenses this file to You under the Apache License, Version 2.0
6+
* (the "License"); you may not use this file except in compliance with
7+
* the License. You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
18+
package extension
19+
20+
import (
21+
"github.com/apache/dubbo-go/cluster"
22+
"github.com/apache/dubbo-go/common"
23+
"github.com/apache/dubbo-go/registry"
24+
)
25+
26+
type registryDirectory func(url *common.URL, registry registry.Registry) (cluster.Directory, error)
27+
28+
var defaultRegistry registryDirectory
29+
30+
// SetDefaultRegistryDirectory ...
31+
func SetDefaultRegistryDirectory(v registryDirectory) {
32+
defaultRegistry = v
33+
}
34+
35+
// GetDefaultRegistryDirectory ...
36+
func GetDefaultRegistryDirectory(config *common.URL, registry registry.Registry) (cluster.Directory, error) {
37+
if defaultRegistry == nil {
38+
panic("registry directory is not existing, make sure you have import the package.")
39+
}
40+
return defaultRegistry(config, registry)
41+
}

common/extension/service_discovery.go

+45
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one or more
3+
* contributor license agreements. See the NOTICE file distributed with
4+
* this work for additional information regarding copyright ownership.
5+
* The ASF licenses this file to You under the Apache License, Version 2.0
6+
* (the "License"); you may not use this file except in compliance with
7+
* the License. You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
18+
package extension
19+
20+
import (
21+
perrors "github.com/pkg/errors"
22+
)
23+
import (
24+
"github.com/apache/dubbo-go/common"
25+
"github.com/apache/dubbo-go/registry"
26+
)
27+
28+
var (
29+
discoveryCreatorMap = make(map[string]func(url *common.URL) (registry.ServiceDiscovery, error), 4)
30+
)
31+
32+
// SetServiceDiscovery will store the creator and name
33+
func SetServiceDiscovery(name string, creator func(url *common.URL) (registry.ServiceDiscovery, error)) {
34+
discoveryCreatorMap[name] = creator
35+
}
36+
37+
// GetServiceDiscovery will return the registry.ServiceDiscovery
38+
// if not found, or initialize instance failed, it will return error.
39+
func GetServiceDiscovery(name string, url *common.URL) (registry.ServiceDiscovery, error) {
40+
creator, ok := discoveryCreatorMap[name]
41+
if !ok {
42+
return nil, perrors.New("Could not find the service discovery with name: " + name)
43+
}
44+
return creator(url)
45+
}

common/proxy/proxy.go

+8-5
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ import (
2525

2626
import (
2727
"github.com/apache/dubbo-go/common"
28+
"github.com/apache/dubbo-go/common/constant"
2829
"github.com/apache/dubbo-go/common/logger"
2930
"github.com/apache/dubbo-go/protocol"
3031
invocation_impl "github.com/apache/dubbo-go/protocol/invocation"
@@ -44,7 +45,7 @@ var (
4445
typError = reflect.Zero(reflect.TypeOf((*error)(nil)).Elem()).Type()
4546
)
4647

47-
// NewProxy ...
48+
// NewProxy create service proxy.
4849
func NewProxy(invoke protocol.Invoker, callBack interface{}, attachments map[string]string) *Proxy {
4950
return &Proxy{
5051
invoke: invoke,
@@ -59,7 +60,6 @@ func NewProxy(invoke protocol.Invoker, callBack interface{}, attachments map[str
5960
// type XxxProvider struct {
6061
// Yyy func(ctx context.Context, args []interface{}, rsp *Zzz) error
6162
// }
62-
6363
func (p *Proxy) Implement(v common.RPCService) {
6464

6565
// check parameters, incoming interface must be a elem's pointer.
@@ -141,14 +141,17 @@ func (p *Proxy) Implement(v common.RPCService) {
141141
}
142142

143143
// add user setAttachment
144-
atm := invCtx.Value("attachment")
144+
atm := invCtx.Value(constant.AttachmentKey)
145145
if m, ok := atm.(map[string]string); ok {
146146
for k, value := range m {
147147
inv.SetAttachments(k, value)
148148
}
149149
}
150150

151151
result := p.invoke.Invoke(invCtx, inv)
152+
if len(result.Attachments()) > 0 {
153+
invCtx = context.WithValue(invCtx, constant.AttachmentKey, result.Attachments())
154+
}
152155

153156
err = result.Error()
154157
logger.Debugf("[makeDubboCallProxy] result: %v, err: %v", result.Result(), err)
@@ -202,12 +205,12 @@ func (p *Proxy) Implement(v common.RPCService) {
202205

203206
}
204207

205-
// Get ...
208+
// Get get rpc service instance.
206209
func (p *Proxy) Get() common.RPCService {
207210
return p.rpc
208211
}
209212

210-
// GetCallback ...
213+
// GetCallback get callback.
211214
func (p *Proxy) GetCallback() interface{} {
212215
return p.callBack
213216
}

common/proxy/proxy_factory.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ import (
2222
"github.com/apache/dubbo-go/protocol"
2323
)
2424

25-
// ProxyFactory ...
25+
// ProxyFactory interface.
2626
type ProxyFactory interface {
2727
GetProxy(invoker protocol.Invoker, url *common.URL) *Proxy
2828
GetAsyncProxy(invoker protocol.Invoker, callBack interface{}, url *common.URL) *Proxy

common/proxy/proxy_factory/default.go

+1
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,7 @@ func (pi *ProxyInvoker) Invoke(ctx context.Context, invocation protocol.Invocati
113113

114114
in := []reflect.Value{svc.Rcvr()}
115115
if method.CtxType() != nil {
116+
ctx = context.WithValue(ctx, constant.AttachmentKey, invocation.Attachments())
116117
in = append(in, method.SuiteContext(ctx))
117118
}
118119

common/rpc_service.go

+14-13
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,6 @@ type AsyncCallback func(response CallbackResponse)
5959
// return map[string][string]{}
6060
// }
6161
const (
62-
// METHOD_MAPPER ...
6362
METHOD_MAPPER = "MethodMapper"
6463
)
6564

@@ -68,7 +67,7 @@ var (
6867
// because Typeof takes an empty interface value. This is annoying.
6968
typeOfError = reflect.TypeOf((*error)(nil)).Elem()
7069

71-
// ServiceMap ...
70+
// ServiceMap store description of service.
7271
// todo: lowerecas?
7372
ServiceMap = &serviceMap{
7473
serviceMap: make(map[string]map[string]*Service),
@@ -80,35 +79,35 @@ var (
8079
// info of method
8180
//////////////////////////
8281

83-
// MethodType ...
82+
// MethodType is description of service method.
8483
type MethodType struct {
8584
method reflect.Method
8685
ctxType reflect.Type // request context
8786
argsType []reflect.Type // args except ctx, include replyType if existing
8887
replyType reflect.Type // return value, otherwise it is nil
8988
}
9089

91-
// Method ...
90+
// Method get @m.method.
9291
func (m *MethodType) Method() reflect.Method {
9392
return m.method
9493
}
9594

96-
// CtxType ...
95+
// CtxType get @m.ctxType.
9796
func (m *MethodType) CtxType() reflect.Type {
9897
return m.ctxType
9998
}
10099

101-
// ArgsType ...
100+
// ArgsType get @m.argsType.
102101
func (m *MethodType) ArgsType() []reflect.Type {
103102
return m.argsType
104103
}
105104

106-
// ReplyType ...
105+
// ReplyType get @m.replyType.
107106
func (m *MethodType) ReplyType() reflect.Type {
108107
return m.replyType
109108
}
110109

111-
// SuiteContext ...
110+
// SuiteContext tranfer @ctx to reflect.Value type or get it from @m.ctxType.
112111
func (m *MethodType) SuiteContext(ctx context.Context) reflect.Value {
113112
if contextv := reflect.ValueOf(ctx); contextv.IsValid() {
114113
return contextv
@@ -120,25 +119,25 @@ func (m *MethodType) SuiteContext(ctx context.Context) reflect.Value {
120119
// info of service interface
121120
//////////////////////////
122121

123-
// Service ...
122+
// Service is description of service
124123
type Service struct {
125124
name string
126125
rcvr reflect.Value
127126
rcvrType reflect.Type
128127
methods map[string]*MethodType
129128
}
130129

131-
// Method ...
130+
// Method get @s.methods.
132131
func (s *Service) Method() map[string]*MethodType {
133132
return s.methods
134133
}
135134

136-
// RcvrType ...
135+
// RcvrType get @s.rcvrType.
137136
func (s *Service) RcvrType() reflect.Type {
138137
return s.rcvrType
139138
}
140139

141-
// Rcvr ...
140+
// Rcvr get @s.rcvr.
142141
func (s *Service) Rcvr() reflect.Value {
143142
return s.rcvr
144143
}
@@ -274,7 +273,9 @@ func (sm *serviceMap) UnRegister(interfaceName, protocol, serviceId string) erro
274273
}
275274
}
276275
delete(svcs, serviceId)
277-
delete(sm.serviceMap, protocol)
276+
if len(sm.serviceMap) == 0 {
277+
delete(sm.serviceMap, protocol)
278+
}
278279

279280
return nil
280281
}

0 commit comments

Comments
 (0)