Skip to content

Commit

Permalink
Merge 9b0e5ea into 9635a6a
Browse files Browse the repository at this point in the history
  • Loading branch information
LaurenceLiZhixin authored Apr 3, 2021
2 parents 9635a6a + 9b0e5ea commit 0c5f3f2
Show file tree
Hide file tree
Showing 27 changed files with 5,622 additions and 15 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/github-actions.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ jobs:
# If you want to matrix build , you can append the following list.
matrix:
go_version:
- 1.13
- 1.15
os:
- ubuntu-latest

Expand Down
1 change: 0 additions & 1 deletion config/config_api_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,6 @@ func TestNewProviderConfig(t *testing.T) {
WithProviderServices("UserProvider", serviceConfig),
WithProviderProtocol("dubbo", "dubbo", "20000"),
WithProviderRegistry("demoConsul", defaultConsulRegistry),
WithProviderRegistry("demoNacos", defaultNacosRegistry),
)

assert.NotNil(t, testProviderConfig.Services)
Expand Down
16 changes: 12 additions & 4 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ module github.com/apache/dubbo-go
go 1.15

require (
github.com/NYTimes/gziphandler v1.1.1 // indirect
github.com/RoaringBitmap/roaring v0.5.5
github.com/Workiva/go-datastructures v1.0.52
github.com/afex/hystrix-go v0.0.0-20180502004556-fa1af6a1f4f5
Expand All @@ -13,41 +14,48 @@ require (
github.com/creasty/defaults v1.5.1
github.com/dubbogo/go-zookeeper v1.0.3
github.com/dubbogo/gost v1.11.2
github.com/dubbogo/triple v0.0.0-20210403061850-372f2dc47e02
github.com/elazarl/go-bindata-assetfs v1.0.0 // indirect
github.com/emicklei/go-restful/v3 v3.4.0
github.com/frankban/quicktest v1.4.1 // indirect
github.com/fsnotify/fsnotify v1.4.9
github.com/go-co-op/gocron v0.1.1
github.com/go-resty/resty/v2 v2.3.0
github.com/golang/mock v1.4.4
github.com/golang/protobuf v1.4.3
github.com/golang/protobuf v1.5.2
github.com/grpc-ecosystem/grpc-opentracing v0.0.0-20180507213350-8e809c8a8645
github.com/hashicorp/consul v1.8.0
github.com/hashicorp/consul/api v1.5.0
github.com/hashicorp/vault/sdk v0.1.14-0.20191112033314-390e96e22eb2
github.com/hashicorp/go-raftchunking v0.6.3-0.20191002164813-7e9e8525653a // indirect
github.com/hashicorp/vault/api v1.0.5-0.20191108163347-bdd38fca2cff // indirect
github.com/hashicorp/vault/sdk v0.1.14-0.20200519221838-e0cfd64bc267
github.com/jinzhu/copier v0.0.0-20190625015134-976e0346caa8
github.com/magiconair/properties v1.8.5
github.com/mitchellh/mapstructure v1.4.1
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd
github.com/nacos-group/nacos-sdk-go v1.0.7
github.com/opentracing/opentracing-go v1.2.0
github.com/pierrec/lz4 v2.2.6+incompatible // indirect
github.com/pkg/errors v0.9.1
github.com/prometheus/client_golang v1.9.0
github.com/satori/go.uuid v1.2.1-0.20181028125025-b2ce2384e17b
github.com/stretchr/objx v0.2.0 // indirect
github.com/stretchr/testify v1.7.0
github.com/zouyx/agollo/v3 v3.4.5
go.uber.org/atomic v1.7.0
go.uber.org/zap v1.16.0
golang.org/x/sys v0.0.0-20201223074533-0d417f636930 // indirect
google.golang.org/grpc v1.33.1
gopkg.in/yaml.v2 v2.4.0
k8s.io/api v0.16.9
k8s.io/apimachinery v0.16.9
k8s.io/client-go v0.16.9
k8s.io/kube-openapi v0.0.0-20191107075043-30be4d16710a // indirect
)

replace (
github.com/coreos/bbolt => go.etcd.io/bbolt v1.3.4
github.com/envoyproxy/go-control-plane => github.com/envoyproxy/go-control-plane v0.8.0
github.com/shirou/gopsutil => github.com/shirou/gopsutil v0.0.0-20181107111621-48177ef5f880
go.etcd.io/bbolt v1.3.4 => github.com/coreos/bbolt v1.3.3
go.etcd.io/bbolt v1.3.4 => github.com/coreos/bbolt v1.3.4
google.golang.org/grpc => google.golang.org/grpc v1.26.0
)
60 changes: 55 additions & 5 deletions go.sum

Large diffs are not rendered by default.

115 changes: 115 additions & 0 deletions protocol/dubbo3/common_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
/*
* 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"
"fmt"
)

import (
triCommon "github.com/dubbogo/triple/pkg/common"
native_grpc "google.golang.org/grpc"
)

import (
"github.com/apache/dubbo-go/config"
"github.com/apache/dubbo-go/protocol"
"github.com/apache/dubbo-go/protocol/dubbo3/internal"
"github.com/apache/dubbo-go/protocol/invocation"
)

// userd dubbo3 biz service
func addService() {
config.SetProviderService(newGreeterProvider())
}

type greeterProvider struct {
*greeterProviderBase
}

func newGreeterProvider() *greeterProvider {
return &greeterProvider{
greeterProviderBase: &greeterProviderBase{},
}
}

func (g *greeterProvider) SayHello(ctx context.Context, req *internal.HelloRequest) (reply *internal.HelloReply, err error) {
fmt.Printf("req: %v", req)
return &internal.HelloReply{Message: "this is message from reply"}, nil
}

func (g *greeterProvider) Reference() string {
return "DubboGreeterImpl"
}

// code generated by greeter.go
type greeterProviderBase struct {
proxyImpl protocol.Invoker
}

func (g *greeterProviderBase) SetProxyImpl(impl protocol.Invoker) {
g.proxyImpl = impl
}

func (g *greeterProviderBase) GetProxyImpl() protocol.Invoker {
return g.proxyImpl
}

func (g *greeterProviderBase) ServiceDesc() *native_grpc.ServiceDesc {
return &native_grpc.ServiceDesc{
ServiceName: "helloworld.Greeter",
HandlerType: (*internal.GreeterServer)(nil),
Methods: []native_grpc.MethodDesc{
{
MethodName: "SayHello",
Handler: dubboGreeterSayHelloHandler,
},
},
Streams: []native_grpc.StreamDesc{},
Metadata: "helloworld.proto",
}
}

func dubboGreeterSayHelloHandler(srv interface{}, ctx context.Context,
dec func(interface{}) error, interceptor native_grpc.UnaryServerInterceptor) (interface{}, error) {

in := new(internal.HelloRequest)
if err := dec(in); err != nil {
return nil, err
}
base := srv.(triCommon.Dubbo3GrpcService)

args := []interface{}{}
args = append(args, in)
invo := invocation.NewRPCInvocation("SayHello", args, nil)

if interceptor == nil {
result := base.GetProxyImpl().Invoke(context.Background(), invo)
return result.Result(), result.Error()
}
info := &native_grpc.UnaryServerInfo{
Server: srv,
FullMethod: "/helloworld.Greeter/SayHello",
}
handler := func(context.Context, interface{}) (interface{}, error) {
result := base.GetProxyImpl().Invoke(context.Background(), invo)
return result.Result(), result.Error()
}
return interceptor(ctx, in, info, handler)
}
61 changes: 61 additions & 0 deletions protocol/dubbo3/dubbo3_exporter.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
/*
* 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 (
tripleCommon "github.com/dubbogo/triple/pkg/common"
)

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 DubboExporter struct {
protocol.BaseExporter
// serviceMap
serviceMap *sync.Map
}

// NewDubboExporter get a Dubbo3Exporter.
func NewDubboExporter(key string, invoker protocol.Invoker, exporterMap *sync.Map, serviceMap *sync.Map) *DubboExporter {
return &DubboExporter{
BaseExporter: *protocol.NewBaseExporter(key, invoker, exporterMap),
serviceMap: serviceMap,
}
}

// Unexport unexport dubbo3 service exporter.
func (de *DubboExporter) 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, tripleCommon.TRIPLE, serviceId)
if err != nil {
logger.Errorf("[DubboExporter.Unexport] error: %v", err)
}
de.serviceMap.Delete(interfaceName)
}
Loading

0 comments on commit 0c5f3f2

Please sign in to comment.