kitex icon indicating copy to clipboard operation
kitex copied to clipboard

[grpc] 无法动态指定 serviceName

Open jxskiss opened this issue 2 years ago • 3 comments

Describe the bug

当使用 kitex 调用下游原生 grpc 服务时,无法动态指定 serviceName,比如使用 "github.com/jhump/protoreflect/grpcreflect" 这个包调用下游 grpc 服务查询 reflection 信息,通过对 kitex client.Client 简单适配可以传给 grpcreflect.NewClientAuto 这个函数使用,但是 grpcreflect 包里会先尝试调用 "/grpc.reflection.v1.ServerReflection/ServerReflectionInfo",如果返回 Unimplemented 错误,再尝试调用 "/grpc.reflection.v1alpha.ServerReflection/ServerReflectionInfo",因为无法指定调用下游 grpc 的 serviceName, method,在不改动 kitex 代码的情况下这个就无法实现。

func (c *serverReflectionClient) ServerReflectionInfo(ctx context.Context, opts ...grpc.CallOption) (ServerReflection_ServerReflectionInfoClient, error) {
	stream, err := c.cc.NewStream(ctx, &ServerReflection_ServiceDesc.Streams[0], "/grpc.reflection.v1.ServerReflection/ServerReflectionInfo", opts...)
	if err != nil {
		return nil, err
	}
	x := &serverReflectionServerReflectionInfoClient{stream}
	return x, nil
}

希望有一种方式可以在调用方法时指定调用的 serviceName, method。同时如果 kitex grpc server 要支持 reflection 和在一个服务实例注册多个 service 的特性,调用侧可能也需要这样的机制指定 serviceName, method。

jxskiss avatar Jan 17 '23 06:01 jxskiss