chickenlj opened a new issue, #2441: URL: https://github.com/apache/dubbo-go/issues/2441
## API 与配置总体结构  ### 确定推荐使用场景 - RPC 就用 server + client(server/client不支持注册中心等任何微服务治理相关能力) - Microservice 就用 instance  ### dubbo 面向用的编程 API,主要用来配置一些全局配置:Application/Registry/Protocol/Metrics 核心用法:dubbo.NewInstance(opts ...dubbo.InstanceOption) ```go func main() { ins, err := dubbo.NewInstance( dubbo.WithName("dubbo_test"), dubbo.WithRegistry("zk", registry.WithZookeeper(), registry.WithAddress("127.0.0.1:2181"), ), dubbo.WithProtocol("tri", protocol.WithTriple(), protocol.WithPort(20000), ), ) } ``` registry/protocol/metrics/等应该由各个package独立开发配置api - [x] registry - [x] protocol - [ ] configcenter? - [ ] metadata? - [ ] metrics? - [ ] 其他? ### server/client 面向用户的编程 API。 主要用来配置: - 各个服务的默认配置,对应之前的 Provider/Consumer - Provider。srv, err := ins.NewServer(server.WithTimeout(5000)) - Consumer。cli, err := client.NewClient( client.WithURL("tri://127.0.0.1:20000"), ) - 每个服务粒度的配置,对应之前的 Service/Reference - Service。greettriple.RegisterGreetServiceHandler(srv, &api.GreetTripleServer{}, server.WithTimeout(5000)) - Reference。greetService.Greet(context.Background(), &greet.GreetRequest{Name: "triple"}, client.WithTimeout(5000)) ```go func main() { // ... srv, err := ins.NewServer(server.WithTimeout(5000)) if err != nil { panic(err) } if err := greettriple.RegisterGreetServiceHandler(srv, &api.GreetTripleServer{}, server.WithTimeout(5000)); err != nil { panic(err) } if err := srv.Serve(); err != nil { panic(err) } } ``` - [ ] server 开放哪些配置?与instance对比如何,是instance的子集,如何确定留下哪些? - 可以只支持 protocol/tls/tracing/metrics/filter/logger 这样rpc层面的配置 - registry/configcenter/metadata 等都必须用instance模式 - [ ] ServiceOption 是 dubbo 区别于 grpc 的一部分,它相对于 ServerOption 而言是服务粒度的,能配置单个服务的一些行为(如注册中心、是否注册等),同时有一些配置项是可以作为默认值影响 CallOption 行为。目前支持的参数有限,是不是要参考 service 进行填充? - [ ] CallOption 目前支持的参数有限,是不是要参考 reference 进行填充? ### global 纯配置,不面向用户 ```go package global // ProtocolConfig is protocol configuration type ProtocolConfig struct { Name string `default:"dubbo" validate:"required" yaml:"name" json:"name,omitempty" property:"name"` Ip string `yaml:"ip" json:"ip,omitempty" property:"ip"` Port string `default:"20000" yaml:"port" json:"port,omitempty" property:"port"` Params interface{} `yaml:"params" json:"params,omitempty" property:"params"` // MaxServerSendMsgSize max size of server send message, 1mb=1000kb=1000000b 1mib=1024kb=1048576b. // more detail to see https://pkg.go.dev/github.com/dustin/go-humanize#pkg-constants MaxServerSendMsgSize string `yaml:"max-server-send-msg-size" json:"max-server-send-msg-size,omitempty"` // MaxServerRecvMsgSize max size of server receive message MaxServerRecvMsgSize string `default:"4mib" yaml:"max-server-recv-msg-size" json:"max-server-recv-msg-size,omitempty"` } func DefaultProtocolConfig() *ProtocolConfig { return &ProtocolConfig{} } type ProtocolOption func(*ProtocolConfig) func WithProtocol_Name(name string) ProtocolOption { return func(cfg *ProtocolConfig) { cfg.Name = name } } func WithProtocol_Ip(ip string) ProtocolOption { return func(cfg *ProtocolConfig) { cfg.Ip = ip } } func WithProtocol_Port(port string) ProtocolOption { return func(cfg *ProtocolConfig) { cfg.Port = port } } func WithProtocol_Params(params interface{}) ProtocolOption { return func(cfg *ProtocolConfig) { cfg.Params = params } } func WithProtocol_MaxServerSendMsgSize(size string) ProtocolOption { return func(cfg *ProtocolConfig) { cfg.MaxServerSendMsgSize = size } } func WithProtocol_MaxServerRecvMsgSize(size string) ProtocolOption { return func(cfg *ProtocolConfig) { cfg.MaxServerRecvMsgSize = size } } ``` - [ ] protocolOption 被 protocol.Option替代了?是不是应该删除? - [ ] 其他类似的配置删除  ### config 包含所有dubbo原始概念和动作,不面向用户(历史用户除外)  这里的 XxxConfig 与 global 中的 XxxConfig 定义存在重复 - global 为何要重复定义一份?因为要作为连接其他层与 config 层的代理,作为一个中间代理避免config与其他层的循环依赖? - 两者的区别,global 中仅包含配置 item,不包含任何 init 动作;global 不依赖任何其他 package。 - 未来的定位,两边在一段时间内会长期存在,职责如上一条所述;除非循环依赖问题已经解决。 配置。 - ~~builder 等用来兼容老行为,废弃~~ - application/registry/provider/consumer/service/reference 作为Config不变,同时包含 init 动作 行为。load (start) -- 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: [email protected] For queries about this service, please contact Infrastructure at: [email protected] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
