You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@dubbo.apache.org by "DMwangnima (via GitHub)" <gi...@apache.org> on 2023/08/09 03:58:24 UTC

[GitHub] [dubbo-go] DMwangnima commented on issue #2375: user-side API enhancement proposal based on new Triple protocol

DMwangnima commented on issue #2375:
URL: https://github.com/apache/dubbo-go/issues/2375#issuecomment-1670616084

   client侧改造要点与解决方案,以pr为例 (https://github.com/apache/dubbo-go/pull/2368/files#diff-bd3a55a72186f59e2e63efb4951573b2f9e4a7cc98086e922b0859f8ccc1dd09) (https://github.com/apache/dubbo-go/pull/2368/files#diff-864ebde43af858aed5bd273d3b76c5591bc28b534dfc1fbe2f3d4ca5ce720ed4) :
   
   抽取出Client包,对应client侧配置结构:Root->Consumer->Reference->Method中的Reference
   Client包的核心API:
   ```go
   Client, err := NewClient(opts ...ReferenceOption)
   ```
   ```go
   Client.Init(info *ClientInfo)
   Client.CallUnary(ctx context.Context, req, resp interface{}, interfaceName, methodName string, opts ...CallOption)
   Client.CallClientStream(ctx context.Context, interfaceName, methodName string, opts ...CallOption)
   Client.CallServerStream(ctx context.Context, req interface{}, interfaceName, methodName string, opts ...CallOption)
   Client.CallBidiStream(ctx context.Context, interfaceName, methodName string, opts ...CallOption)
   ```
   ```go
   type ClientInfo struct {
   	InterfaceName    string
   	MethodNames      []string
   	ClientInjectFunc func(dubboCliRaw interface{}, cli *Client)
   	Meta             map[string]interface{}
   }
   ```
   其中ReferenceOption对ReferenceConfig进行配置,ClientInfo包含去除反射所需的元数据。
   用户使用NewClient配合ReferenceOption进行配置生成Client对象,将Client对象传入IDL生成代码,生成代码调用Client.Init进行初始化,调用Client.CallUnary、Client.CallClientStream、Client.CallServerStream、Client.CallBidiStream完成真正的rpc调用。
   通过这种方式,用户只需要理解Client这一个概念,IDL生成代码中去除了GetInvoker,配置invoker链中的反射流程也由ClientInfo中的元数据取代。
   此时Client成为串联用户配置与IDL生成代码的唯一概念,用户侧代码如下所示:
   ```go
   cli, err := client.NewClient(
   	client.WithURL("127.0.0.1:8080"),
   )
   dubboCli, err := greettriple.NewGreetServiceClient(cli)
   if err != nil {
   	panic(err)
   }
   ```
   
   
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org
For additional commands, e-mail: notifications-help@dubbo.apache.org