Skip to content
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 0 additions & 11 deletions protocol/dubbo3/internal/client.go
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why not just delete this file

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK 那我就直接删除了

Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,3 @@
*/

package internal

import (
"dubbo.apache.org/dubbo-go/v3/config"
)

// TODO: After the config is removed, remove the test
func init() {
// for pb client
config.SetConsumerServiceByInterfaceName("org.apache.dubbo.DubboGreeterImpl", &GreeterClientImpl{})
config.SetConsumerService(&GreeterClientImpl{})
}
26 changes: 0 additions & 26 deletions protocol/dubbo3/internal/server.go
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这几个internal路径里面的文件是用来干嘛的

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

简单概括一下,大概是这些

protocol/dubbo3/internal/client.go
Dubbo3 客户端初始化,完成服务发现、调用参数封装,为 RPC 调用做准备

protocol/dubbo3/internal/server.go
Dubbo3 服务端启动逻辑,实现 SayHello 服务,绑定端口并监听客户端请求

protocol/grpc/internal/helloworld/client.go
gRPC 基础客户端,建立连接,用于发起普通 gRPC 请求

protocol/grpc/internal/routeguide/client.go
gRPC 流式客户端示例,实现服务端流、客户端流、双向流三种通信模式

Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,6 @@ import (
)

import (
"dubbo.apache.org/dubbo-go/v3/common"
"dubbo.apache.org/dubbo-go/v3/config"
_ "dubbo.apache.org/dubbo-go/v3/filter/filter_impl"
_ "dubbo.apache.org/dubbo-go/v3/metrics/prometheus"
_ "dubbo.apache.org/dubbo-go/v3/proxy/proxy_factory"
Expand All @@ -43,27 +41,3 @@ func (s *Server) SayHello(ctx context.Context, in *HelloRequest) (*HelloReply, e
log.Infof("Received: %v", in.GetName())
return &HelloReply{Message: "Hello " + in.GetName()}, nil
}

// InitDubboServer creates global gRPC server.
// TODO: After the config is removed, remove the test
func InitDubboServer() {
serviceConfig := config.NewServiceConfigBuilder().
SetInterface("org.apache.dubbo.DubboGreeterImpl").
SetProtocolIDs("tripleKey").Build()

providerConfig := config.NewProviderConfigBuilder().SetServices(map[string]*config.ServiceConfig{
common.GetReference(&Server{}): serviceConfig,
}).Build()

protocolConfig := config.NewProtocolConfigBuilder().SetName("tri").SetPort("20003").Build()

rootConfig := config.NewRootConfigBuilder().SetProvider(providerConfig).SetProtocols(map[string]*config.ProtocolConfig{
"tripleKey": protocolConfig,
}).Build()

config.SetProviderService(&Server{})
if err := rootConfig.Init(); err != nil {
panic(err)
}
rootConfig.Start()
}
23 changes: 19 additions & 4 deletions protocol/grpc/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -214,9 +214,24 @@ func clientInit(url *common.URL) {
}

func getInvoker(impl any, conn *grpc.ClientConn) any {
var in []reflect.Value
in = append(in, reflect.ValueOf(conn))
method := reflect.ValueOf(impl).MethodByName("GetDubboStub")
res := method.Call(in)
if impl == nil {
return nil
}

implValue := reflect.ValueOf(impl)
if !implValue.IsValid() {
return nil
}

method := implValue.MethodByName("GetDubboStub")
if !method.IsValid() {
return nil
}

res := method.Call([]reflect.Value{reflect.ValueOf(conn)})
if len(res) == 0 {
return nil
}

return res[0].Interface()
}
6 changes: 2 additions & 4 deletions protocol/grpc/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,7 @@ func TestUnaryClient(t *testing.T) {
cli, err := NewClient(url)
require.NoError(t, err)

impl := &helloworld.GreeterClientImpl{}
client := impl.GetDubboStub(cli.ClientConn)
client := helloworld.NewGreeterClient(cli.ClientConn)
result, err := client.SayHello(context.Background(), &helloworld.HelloRequest{Name: "request name"})
require.NoError(t, err)
assert.Equal(t, &helloworld.HelloReply{Message: "Hello request name"}, result)
Expand All @@ -67,8 +66,7 @@ func TestStreamClient(t *testing.T) {
cli, err := NewClient(url)
require.NoError(t, err)

impl := &routeguide.RouteGuideClientImpl{}
client := impl.GetDubboStub(cli.ClientConn)
client := routeguide.NewRouteGuideClient(cli.ClientConn)

result, err := client.GetFeature(context.Background(), &routeguide.Point{Latitude: 409146138, Longitude: -746188906})
require.NoError(t, err)
Expand Down
12 changes: 12 additions & 0 deletions protocol/grpc/grpc_invoker.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ package grpc

import (
"context"
"fmt"
"reflect"
"sync"
)
Expand All @@ -40,6 +41,7 @@ import (
)

var errNoReply = errors.New("request need @response")
var errNoInvoker = errors.New("grpc client invoker is not initialized")

// GrpcInvoker is a gRPC invoker wrapping a generated client and guarding its lifecycle.
type GrpcInvoker struct {
Expand Down Expand Up @@ -98,8 +100,18 @@ func (gi *GrpcInvoker) Invoke(ctx context.Context, invocation base.Invocation) r
in = append(in, reflect.ValueOf(ctx))
in = append(in, invocation.ParameterValues()...)

if !client.invoker.IsValid() {
result.SetError(errNoInvoker)
return &result
}

methodName := invocation.MethodName()
method := client.invoker.MethodByName(methodName)
if !method.IsValid() {
result.SetError(fmt.Errorf("grpc method %s not found on invoker", methodName))
return &result
}

res := method.Call(in)

result.SetResult(res[0])
Expand Down
2 changes: 2 additions & 0 deletions protocol/grpc/grpc_invoker_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ func TestUnaryInvoke(t *testing.T) {

cli, err := NewClient(url)
require.NoError(t, err)
cli.invoker = reflect.ValueOf(helloworld.NewGreeterClient(cli.ClientConn))

var args []reflect.Value
args = append(args, reflect.ValueOf(&helloworld.HelloRequest{Name: "request name"}))
Expand Down Expand Up @@ -88,6 +89,7 @@ func TestStreamInvoke(t *testing.T) {

cli, err := NewClient(url)
require.NoError(t, err)
cli.invoker = reflect.ValueOf(routeguide.NewRouteGuideClient(cli.ClientConn))

invoker := NewGrpcInvoker(url, cli)

Expand Down
9 changes: 0 additions & 9 deletions protocol/grpc/internal/helloworld/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,6 @@ import (
"google.golang.org/grpc"
)

import (
"dubbo.apache.org/dubbo-go/v3/config"
)

func init() {
config.SetConsumerServiceByInterfaceName("io.grpc.examples.helloworld.GreeterGrpc$IGreeter", &GrpcGreeterImpl{})
config.SetConsumerService(&GrpcGreeterImpl{})
}

// GrpcGreeterImpl
// used for dubbo-grpc biz client
type GrpcGreeterImpl struct {
Expand Down
9 changes: 0 additions & 9 deletions protocol/grpc/internal/routeguide/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,6 @@ import (
log "github.com/dubbogo/gost/log/logger"
)

import (
"dubbo.apache.org/dubbo-go/v3/config"
)

func init() {
config.SetConsumerServiceByInterfaceName("io.grpc.examples.helloworld.GreeterGrpc$RouteGuide", &RouteGuideClientImpl{})
config.SetConsumerService(&RouteGuideClientImpl{})
}

// PrintFeatures lists all the features within the given bounding Rectangle.
func PrintFeatures(stream RouteGuide_ListFeaturesClient) {
for {
Expand Down
Loading