-
Notifications
You must be signed in to change notification settings - Fork 933
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
Ftr: dubbogo 3.0 Triple support #959
Changes from 28 commits
98977d0
0249c47
1afdcc2
9d3fefd
8dbf73b
43ef202
4b0bdfb
150a89f
0ff136d
9bf076c
8f916e6
68ff8be
c46d479
006e4a5
ba96f44
bb7bf3e
c4fa94c
7108241
dfc418d
25ed35d
240695c
85eadf4
c7fd69a
c593464
29e6cff
6ab25e4
08a13cf
0d7baa5
8e0aa32
60f53ab
f4d5df2
068505d
36e6c4c
4ea5d0a
1156b92
af608d8
784cf6e
37a11a1
1c95b6a
2301f67
9e0fd61
a5bd416
2a924dc
329710a
fb13085
837cda3
f7995eb
c990022
1f708d7
3de6c8a
55e861a
ab774b5
5ffcdfe
a136af5
0cb6305
b5365b3
7fc8fd4
e6bd72e
0d9d7c0
e2954fe
cfef02a
2f432d5
4d50436
8dffc29
75713b9
01684bf
52405be
5e76af9
ce90b4b
30730a3
5683e9f
f244915
b8f21c4
04fa9b0
ad8a8ad
1cc462b
b2b70d2
f7938a3
78b29c7
afab2dc
8789da2
5a7f093
93932e1
27ddd69
9fa3896
95432d1
f734264
551b073
766c2ca
0ecbcef
45cfa0a
b4f304e
da3d9fc
99a0253
f8c8593
ea5e28b
59d4e4e
93e9534
badd37b
dcd0c02
244b495
ed97c95
de2dad9
44f7199
a883dc3
98184aa
0bed115
076b9a5
c3da749
2d2337d
1211616
49b2244
377c9e1
313c4c1
eaadca7
2b8d962
d6bf494
af6b6c0
8aba190
2282bce
a5ea0d8
a9d27ab
7906db6
65c8998
61737f8
677d7e8
c145691
b353ac9
a2df3f1
ba7eab7
66b5283
cc7fb2e
668e085
e308e19
9ae3c90
3cb769a
56f23ed
4ae1b41
a9b1e1c
4a0c97f
35d31fe
1c1c7d3
8d0ccff
425c03f
bdd3546
2e1e474
8884462
1253721
407d234
36129b9
69026e8
971c854
a08392c
8eb6107
b4accad
2acf10a
ca71862
b6022bb
9e40791
9ef971c
780a05c
96a6c30
f11f1f9
ded3c49
838c847
41fd617
34fa1da
5d6b250
266d773
85a21e8
f0ddf36
0960b23
082a0bd
3d7aa03
41016aa
556c369
44e9f5d
34bd21c
e633a73
2eacd35
7b67e09
374a01a
b704cad
d305b67
a191eaf
92389d2
c8fb3e9
808370a
2b559fc
794ab77
6288e18
fd28d58
5919b11
bbd698d
c81fde1
c26d24d
17825e9
a3bc853
109d1dc
5cb723a
3dc2f17
9d5dc61
f6e0db0
bfbe4e9
7dd17b3
aaacf31
982e74c
4a721a2
36c0681
969ff84
55737aa
016bcce
3111854
b21ce4e
9c40c29
0cb6edb
f354f90
fec0532
c1f25f6
d136504
9a666eb
43b931e
a7abcc1
bbda967
80ee534
92a6231
882930c
9a980ff
3907104
dd1b395
6c989b9
ec2a259
9130466
4f9b8d9
0b38e93
c3d2177
27d7746
d6941b2
17c4a9e
65cd856
25eb01d
9e9c7f6
a2ebe57
5ecf6fd
08eb7a0
69019ce
f794555
a5cc93a
f457e55
22f6546
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one or more | ||
* contributor license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright ownership. | ||
* The ASF licenses this file to You under the Apache License, Version 2.0 | ||
* (the "License"); you may not use this file except in compliance with | ||
* the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package dubbo3 | ||
|
||
import ( | ||
"sync" | ||
) | ||
|
||
import ( | ||
"github.com/apache/dubbo-go/common" | ||
"github.com/apache/dubbo-go/common/constant" | ||
"github.com/apache/dubbo-go/common/logger" | ||
"github.com/apache/dubbo-go/protocol" | ||
) | ||
|
||
// DubboExporter is dubbo3 service exporter. | ||
type Dubbo3Exporter struct { | ||
protocol.BaseExporter | ||
} | ||
|
||
// NewDubbo3Exporter get a Dubbo3Exporter. | ||
func NewDubbo3Exporter(key string, invoker protocol.Invoker, exporterMap *sync.Map) *Dubbo3Exporter { | ||
return &Dubbo3Exporter{ | ||
BaseExporter: *protocol.NewBaseExporter(key, invoker, exporterMap), | ||
} | ||
} | ||
|
||
// Unexport unexport dubbo3 service exporter. | ||
func (de *Dubbo3Exporter) Unexport() { | ||
url := de.GetInvoker().GetUrl() | ||
serviceId := url.GetParam(constant.BEAN_NAME_KEY, "") | ||
interfaceName := url.GetParam(constant.INTERFACE_KEY, "") | ||
de.BaseExporter.Unexport() | ||
err := common.ServiceMap.UnRegister(interfaceName, DUBBO3, serviceId) | ||
if err != nil { | ||
logger.Errorf("[DubboExporter.Unexport] error: %v", err) | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,142 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one or more | ||
* contributor license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright ownership. | ||
* The ASF licenses this file to You under the Apache License, Version 2.0 | ||
* (the "License"); you may not use this file except in compliance with | ||
* the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package dubbo3 | ||
|
||
import ( | ||
"context" | ||
"reflect" | ||
"strconv" | ||
"strings" | ||
"sync" | ||
"time" | ||
) | ||
|
||
import ( | ||
hessian2 "github.com/apache/dubbo-go-hessian2" | ||
) | ||
|
||
import ( | ||
"github.com/apache/dubbo-go/common" | ||
"github.com/apache/dubbo-go/common/constant" | ||
"github.com/apache/dubbo-go/common/logger" | ||
"github.com/apache/dubbo-go/config" | ||
"github.com/apache/dubbo-go/protocol" | ||
invocation_impl "github.com/apache/dubbo-go/protocol/invocation" | ||
"github.com/apache/dubbo-go/remoting/dubbo3" | ||
) | ||
|
||
// Dubbo3Invoker is implement of protocol.Invoker. A dubboInvoker refer to one service and ip. | ||
type Dubbo3Invoker struct { | ||
protocol.BaseInvoker | ||
// the exchange layer, it is focus on network communication. | ||
client *dubbo3.TripleClient | ||
quitOnce sync.Once | ||
// timeout for service(interface) level. | ||
timeout time.Duration | ||
// Used to record the number of requests. -1 represent this DubboInvoker is destroyed | ||
reqNum int64 | ||
} | ||
|
||
// NewDubbo3Invoker constructor | ||
func NewDubbo3Invoker(url *common.URL) (*Dubbo3Invoker, error) { | ||
requestTimeout := config.GetConsumerConfig().RequestTimeout | ||
requestTimeoutStr := url.GetParam(constant.TIMEOUT_KEY, config.GetConsumerConfig().Request_Timeout) | ||
if t, err := time.ParseDuration(requestTimeoutStr); err == nil { | ||
requestTimeout = t | ||
} | ||
|
||
client, err := dubbo3.NewTripleClient(url) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
return &Dubbo3Invoker{ | ||
BaseInvoker: *protocol.NewBaseInvoker(url), | ||
client: client, | ||
reqNum: 0, | ||
timeout: requestTimeout, | ||
}, nil | ||
} | ||
|
||
// Invoke call remoting. | ||
func (di *Dubbo3Invoker) Invoke(ctx context.Context, invocation protocol.Invocation) protocol.Result { | ||
var ( | ||
result protocol.RPCResult | ||
) | ||
|
||
in := make([]reflect.Value, 0, 16) | ||
in = append(in, reflect.ValueOf(ctx)) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. using 'in := append(in, reflect.ValueOf(ctx))' instead There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. r u sure? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. change it as ur idea |
||
if len(invocation.ParameterValues()) > 0 { | ||
in = append(in, invocation.ParameterValues()...) | ||
} | ||
|
||
methodName := invocation.MethodName() | ||
method := di.client.Invoker.MethodByName(methodName) | ||
res := method.Call(in) | ||
|
||
result.Rest = res[0] | ||
// check err | ||
if !res[1].IsNil() { | ||
result.Err = res[1].Interface().(error) | ||
} else { | ||
_ = hessian2.ReflectResponse(res[0], invocation.Reply()) | ||
} | ||
|
||
return &result | ||
} | ||
|
||
// get timeout including methodConfig | ||
func (di *Dubbo3Invoker) getTimeout(invocation *invocation_impl.RPCInvocation) time.Duration { | ||
timeout := di.GetUrl().GetParam(strings.Join([]string{constant.METHOD_KEYS, invocation.MethodName(), constant.TIMEOUT_KEY}, "."), "") | ||
if len(timeout) != 0 { | ||
if t, err := time.ParseDuration(timeout); err == nil { | ||
// config timeout into attachment | ||
invocation.SetAttachments(constant.TIMEOUT_KEY, strconv.Itoa(int(t.Milliseconds()))) | ||
return t | ||
} | ||
} | ||
// set timeout into invocation at method level | ||
invocation.SetAttachments(constant.TIMEOUT_KEY, strconv.Itoa(int(di.timeout.Milliseconds()))) | ||
return di.timeout | ||
} | ||
|
||
// IsAvailable check if invoker is available, now it is useless | ||
func (di *Dubbo3Invoker) IsAvailable() bool { | ||
return di.client.IsAvailable() | ||
} | ||
|
||
// Destroy destroy dubbo3 client invoker. | ||
func (di *Dubbo3Invoker) Destroy() { | ||
di.quitOnce.Do(func() { | ||
for { | ||
if di.reqNum == 0 { | ||
di.reqNum = -1 | ||
logger.Infof("dubboInvoker is destroyed,url:{%s}", di.GetUrl().Key()) | ||
di.BaseInvoker.Destroy() | ||
if di.client != nil { | ||
di.client.Close() | ||
di.client = nil | ||
} | ||
break | ||
} | ||
logger.Warnf("DubboInvoker is to be destroyed, wait {%v} req end,url:{%s}", di.reqNum, di.GetUrl().Key()) | ||
time.Sleep(1 * time.Second) | ||
} | ||
|
||
}) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think dubbo3_exporter.go should change to dubbo_exporter.go, like other protocol, the package dubbo3 is enough.