Skip to content

Commit f09fd71

Browse files
authored
Merge pull request #1071 from LaurenceLiZhixin/Ftr/triple
Ftr: Triple Protocol Support
2 parents f7ae84a + 6619560 commit f09fd71

27 files changed

+5621
-41
lines changed

.github/workflows/github-actions.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ jobs:
1515
# If you want to matrix build , you can append the following list.
1616
matrix:
1717
go_version:
18-
- 1.13
18+
- 1.15
1919
os:
2020
- ubuntu-latest
2121

config/config_api_test.go

-1
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,6 @@ func TestNewProviderConfig(t *testing.T) {
151151
WithProviderServices("UserProvider", serviceConfig),
152152
WithProviderProtocol("dubbo", "dubbo", "20000"),
153153
WithProviderRegistry("demoConsul", defaultConsulRegistry),
154-
WithProviderRegistry("demoNacos", defaultNacosRegistry),
155154
)
156155

157156
assert.NotNil(t, testProviderConfig.Services)

go.mod

+12-5
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ module github.com/apache/dubbo-go
33
go 1.15
44

55
require (
6+
github.com/NYTimes/gziphandler v1.1.1 // indirect
67
github.com/RoaringBitmap/roaring v0.5.5
78
github.com/Workiva/go-datastructures v1.0.52
89
github.com/afex/hystrix-go v0.0.0-20180502004556-fa1af6a1f4f5
@@ -13,42 +14,48 @@ require (
1314
github.com/creasty/defaults v1.5.1
1415
github.com/dubbogo/go-zookeeper v1.0.3
1516
github.com/dubbogo/gost v1.11.3
17+
github.com/dubbogo/triple v0.0.0-20210403061850-372f2dc47e02
1618
github.com/elazarl/go-bindata-assetfs v1.0.0 // indirect
1719
github.com/emicklei/go-restful/v3 v3.4.0
20+
github.com/frankban/quicktest v1.4.1 // indirect
1821
github.com/fsnotify/fsnotify v1.4.9
1922
github.com/go-co-op/gocron v0.1.1
2023
github.com/go-resty/resty/v2 v2.3.0
2124
github.com/golang/mock v1.4.4
22-
github.com/golang/protobuf v1.4.3
25+
github.com/golang/protobuf v1.5.2
2326
github.com/grpc-ecosystem/grpc-opentracing v0.0.0-20180507213350-8e809c8a8645
2427
github.com/hashicorp/consul v1.8.0
2528
github.com/hashicorp/consul/api v1.5.0
26-
github.com/hashicorp/vault/sdk v0.1.14-0.20191112033314-390e96e22eb2
29+
github.com/hashicorp/go-raftchunking v0.6.3-0.20191002164813-7e9e8525653a // indirect
30+
github.com/hashicorp/vault/api v1.0.5-0.20191108163347-bdd38fca2cff // indirect
31+
github.com/hashicorp/vault/sdk v0.1.14-0.20200519221838-e0cfd64bc267
2732
github.com/jinzhu/copier v0.0.0-20190625015134-976e0346caa8
2833
github.com/magiconair/properties v1.8.5
2934
github.com/mitchellh/mapstructure v1.4.1
3035
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd
3136
github.com/nacos-group/nacos-sdk-go v1.0.7
3237
github.com/opentracing/opentracing-go v1.2.0
38+
github.com/pierrec/lz4 v2.2.6+incompatible // indirect
3339
github.com/pkg/errors v0.9.1
3440
github.com/prometheus/client_golang v1.9.0
3541
github.com/satori/go.uuid v1.2.1-0.20181028125025-b2ce2384e17b
42+
github.com/stretchr/objx v0.2.0 // indirect
3643
github.com/stretchr/testify v1.7.0
3744
github.com/zouyx/agollo/v3 v3.4.5
3845
go.uber.org/atomic v1.7.0
3946
go.uber.org/zap v1.16.0
40-
golang.org/x/sys v0.0.0-20201223074533-0d417f636930 // indirect
4147
google.golang.org/grpc v1.33.1
4248
gopkg.in/yaml.v2 v2.4.0
4349
k8s.io/api v0.16.9
4450
k8s.io/apimachinery v0.16.9
4551
k8s.io/client-go v0.16.9
52+
k8s.io/kube-openapi v0.0.0-20191107075043-30be4d16710a // indirect
4653
)
4754

4855
replace (
4956
github.com/coreos/bbolt => go.etcd.io/bbolt v1.3.4
5057
github.com/envoyproxy/go-control-plane => github.com/envoyproxy/go-control-plane v0.8.0
5158
github.com/shirou/gopsutil => github.com/shirou/gopsutil v0.0.0-20181107111621-48177ef5f880
52-
go.etcd.io/bbolt v1.3.4 => github.com/coreos/bbolt v1.3.3
53-
google.golang.org/grpc v1.33.1 => google.golang.org/grpc v1.26.0
59+
go.etcd.io/bbolt v1.3.4 => github.com/coreos/bbolt v1.3.4
60+
google.golang.org/grpc => google.golang.org/grpc v1.26.0
5461
)

go.sum

+54-30
Large diffs are not rendered by default.

protocol/dubbo3/common_test.go

+115
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,115 @@
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 dubbo3
19+
20+
import (
21+
"context"
22+
"fmt"
23+
)
24+
25+
import (
26+
triCommon "github.com/dubbogo/triple/pkg/common"
27+
native_grpc "google.golang.org/grpc"
28+
)
29+
30+
import (
31+
"github.com/apache/dubbo-go/config"
32+
"github.com/apache/dubbo-go/protocol"
33+
"github.com/apache/dubbo-go/protocol/dubbo3/internal"
34+
"github.com/apache/dubbo-go/protocol/invocation"
35+
)
36+
37+
// userd dubbo3 biz service
38+
func addService() {
39+
config.SetProviderService(newGreeterProvider())
40+
}
41+
42+
type greeterProvider struct {
43+
*greeterProviderBase
44+
}
45+
46+
func newGreeterProvider() *greeterProvider {
47+
return &greeterProvider{
48+
greeterProviderBase: &greeterProviderBase{},
49+
}
50+
}
51+
52+
func (g *greeterProvider) SayHello(ctx context.Context, req *internal.HelloRequest) (reply *internal.HelloReply, err error) {
53+
fmt.Printf("req: %v", req)
54+
return &internal.HelloReply{Message: "this is message from reply"}, nil
55+
}
56+
57+
func (g *greeterProvider) Reference() string {
58+
return "DubboGreeterImpl"
59+
}
60+
61+
// code generated by greeter.go
62+
type greeterProviderBase struct {
63+
proxyImpl protocol.Invoker
64+
}
65+
66+
func (g *greeterProviderBase) SetProxyImpl(impl protocol.Invoker) {
67+
g.proxyImpl = impl
68+
}
69+
70+
func (g *greeterProviderBase) GetProxyImpl() protocol.Invoker {
71+
return g.proxyImpl
72+
}
73+
74+
func (g *greeterProviderBase) ServiceDesc() *native_grpc.ServiceDesc {
75+
return &native_grpc.ServiceDesc{
76+
ServiceName: "helloworld.Greeter",
77+
HandlerType: (*internal.GreeterServer)(nil),
78+
Methods: []native_grpc.MethodDesc{
79+
{
80+
MethodName: "SayHello",
81+
Handler: dubboGreeterSayHelloHandler,
82+
},
83+
},
84+
Streams: []native_grpc.StreamDesc{},
85+
Metadata: "helloworld.proto",
86+
}
87+
}
88+
89+
func dubboGreeterSayHelloHandler(srv interface{}, ctx context.Context,
90+
dec func(interface{}) error, interceptor native_grpc.UnaryServerInterceptor) (interface{}, error) {
91+
92+
in := new(internal.HelloRequest)
93+
if err := dec(in); err != nil {
94+
return nil, err
95+
}
96+
base := srv.(triCommon.Dubbo3GrpcService)
97+
98+
args := []interface{}{}
99+
args = append(args, in)
100+
invo := invocation.NewRPCInvocation("SayHello", args, nil)
101+
102+
if interceptor == nil {
103+
result := base.GetProxyImpl().Invoke(context.Background(), invo)
104+
return result.Result(), result.Error()
105+
}
106+
info := &native_grpc.UnaryServerInfo{
107+
Server: srv,
108+
FullMethod: "/helloworld.Greeter/SayHello",
109+
}
110+
handler := func(context.Context, interface{}) (interface{}, error) {
111+
result := base.GetProxyImpl().Invoke(context.Background(), invo)
112+
return result.Result(), result.Error()
113+
}
114+
return interceptor(ctx, in, info, handler)
115+
}

protocol/dubbo3/dubbo3_exporter.go

+61
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
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 dubbo3
19+
20+
import (
21+
"sync"
22+
)
23+
24+
import (
25+
tripleCommon "github.com/dubbogo/triple/pkg/common"
26+
)
27+
28+
import (
29+
"github.com/apache/dubbo-go/common"
30+
"github.com/apache/dubbo-go/common/constant"
31+
"github.com/apache/dubbo-go/common/logger"
32+
"github.com/apache/dubbo-go/protocol"
33+
)
34+
35+
// DubboExporter is dubbo3 service exporter.
36+
type DubboExporter struct {
37+
protocol.BaseExporter
38+
// serviceMap
39+
serviceMap *sync.Map
40+
}
41+
42+
// NewDubboExporter get a Dubbo3Exporter.
43+
func NewDubboExporter(key string, invoker protocol.Invoker, exporterMap *sync.Map, serviceMap *sync.Map) *DubboExporter {
44+
return &DubboExporter{
45+
BaseExporter: *protocol.NewBaseExporter(key, invoker, exporterMap),
46+
serviceMap: serviceMap,
47+
}
48+
}
49+
50+
// Unexport unexport dubbo3 service exporter.
51+
func (de *DubboExporter) Unexport() {
52+
url := de.GetInvoker().GetUrl()
53+
serviceId := url.GetParam(constant.BEAN_NAME_KEY, "")
54+
interfaceName := url.GetParam(constant.INTERFACE_KEY, "")
55+
de.BaseExporter.Unexport()
56+
err := common.ServiceMap.UnRegister(interfaceName, tripleCommon.TRIPLE, serviceId)
57+
if err != nil {
58+
logger.Errorf("[DubboExporter.Unexport] error: %v", err)
59+
}
60+
de.serviceMap.Delete(interfaceName)
61+
}

0 commit comments

Comments
 (0)