diff --git a/client/invoker/invoker.go b/client/invoker/invoker.go index 728e42d08d898dbba8570e6cdadc31b2eecfcfcb..a535f9363f90a36acc108ef5bcd24bcbe6c10f06 100644 --- a/client/invoker/invoker.go +++ b/client/invoker/invoker.go @@ -146,7 +146,7 @@ func (ivk *Invoker) update(res *registry.ServiceEvent) { } } -func (ivk *Invoker) getService(registryConf registry.ServiceConfig) (*ServiceArray, error) { +func (ivk *Invoker) getService(registryConf registry.DefaultServiceConfig) (*ServiceArray, error) { defer ivk.listenerLock.Unlock() registryKey := registryConf.Key() @@ -174,7 +174,7 @@ func (ivk *Invoker) getService(registryConf registry.ServiceConfig) (*ServiceArr return newSvcArr, nil } -func (ivk *Invoker) HttpCall(ctx context.Context, reqId int64, registryConf registry.ServiceConfig, req jsonrpc.Request, resp interface{}) error { +func (ivk *Invoker) HttpCall(ctx context.Context, reqId int64, registryConf registry.DefaultServiceConfig, req jsonrpc.Request, resp interface{}) error { registryArray, err := ivk.getService(registryConf) if err != nil { @@ -195,7 +195,7 @@ func (ivk *Invoker) HttpCall(ctx context.Context, reqId int64, registryConf regi return nil } -func (ivk *Invoker) DubboCall(reqId int64, registryConf registry.ServiceConfig, method string, args, reply interface{}, opts ...dubbo.CallOption) error { +func (ivk *Invoker) DubboCall(reqId int64, registryConf registry.DefaultServiceConfig, method string, args, reply interface{}, opts ...dubbo.CallOption) error { registryArray, err := ivk.getService(registryConf) if err != nil { diff --git a/examples/client_config.go b/examples/client_config.go index 859d8af23466b15a5dfaadae313f2f6d52f3758c..fb8c1d6458ba270471028e2d4f282f2444e0b735 100644 --- a/examples/client_config.go +++ b/examples/client_config.go @@ -50,7 +50,7 @@ type ( Application_Config registry.ApplicationConfig `yaml:"application_config" json:"application_config,omitempty"` ZkRegistryConfig zookeeper.ZkRegistryConfig `yaml:"zk_registry_config" json:"zk_registry_config,omitempty"` // 一个客户端只允许使用一个service的其中一个group和其中一个version - Service_List []registry.ServiceConfig `yaml:"service_list" json:"service_list,omitempty"` + Service_List []registry.DefaultServiceConfig `yaml:"service_list" json:"service_list,omitempty"` } ) diff --git a/examples/dubbo/go-client/app/test.go b/examples/dubbo/go-client/app/test.go index 1154da0975f18a52cccf73f0c0079e4ffd968850..aafd05db595a32a75e0279a7c178c083cc0cc28f 100644 --- a/examples/dubbo/go-client/app/test.go +++ b/examples/dubbo/go-client/app/test.go @@ -26,7 +26,7 @@ func testDubborpc(clientConfig *examples.ClientConfig, userKey string) { method string serviceIdx int user *DubboUser - conf registry.ServiceConfig + conf registry.DefaultServiceConfig ) serviceIdx = -1 svc = "com.ikurento.user.UserProvider" @@ -42,7 +42,7 @@ func testDubborpc(clientConfig *examples.ClientConfig, userKey string) { // Create request method = string("GetUser") - conf = registry.ServiceConfig{ + conf = registry.DefaultServiceConfig{ Group: clientConfig.Service_List[serviceIdx].Group, Protocol: public.CodecType(public.CODECTYPE_DUBBO).String(), Version: clientConfig.Service_List[serviceIdx].Version, diff --git a/examples/jsonrpc/go-client/app/test.go b/examples/jsonrpc/go-client/app/test.go index 2c662c9e9d86ce266caa5e42e6f1216fe3c75478..95a78f29adfa462fdc956a5a601a6bf3ec6277cd 100644 --- a/examples/jsonrpc/go-client/app/test.go +++ b/examples/jsonrpc/go-client/app/test.go @@ -24,7 +24,7 @@ func testJsonrpc(clientConfig *examples.ClientConfig, userKey string, method str serviceIdx int user *JsonRPCUser ctx context.Context - conf registry.ServiceConfig + conf registry.DefaultServiceConfig req jsonrpc.Request ) @@ -42,7 +42,7 @@ func testJsonrpc(clientConfig *examples.ClientConfig, userKey string, method str // Create request // gxlog.CInfo("jsonrpc selected service %#v", clientConfig.Service_List[serviceIdx]) - conf = registry.ServiceConfig{ + conf = registry.DefaultServiceConfig{ Group: clientConfig.Service_List[serviceIdx].Group, Protocol: public.CodecType(public.CODECTYPE_JSONRPC).String(), Version: clientConfig.Service_List[serviceIdx].Version, diff --git a/examples/jsonrpc/go-server/app/config.go b/examples/jsonrpc/go-server/app/config.go index 08c2d85660893483bdc8188e7b8933f847052cad..ff69320cb2f11f08e9f6e375a4a7538ede07d430 100644 --- a/examples/jsonrpc/go-server/app/config.go +++ b/examples/jsonrpc/go-server/app/config.go @@ -43,10 +43,10 @@ type ( // application Application_Config registry.ApplicationConfig `yaml:"application_config" json:"application_config,omitempty"` // Registry_Address string `default:"192.168.35.3:2181"` - Registry string `default:"zookeeper" yaml:"registry" json:"registry,omitempty"` - ZkRegistryConfig zookeeper.ZkRegistryConfig `yaml:"zk_registry_config" json:"zk_registry_config,omitempty"` - Service_List []registry.ServiceConfig `yaml:"service_list" json:"service_list,omitempty"` - Server_List []server.ServerConfig `yaml:"server_list" json:"server_list,omitempty"` + Registry string `default:"zookeeper" yaml:"registry" json:"registry,omitempty"` + ZkRegistryConfig zookeeper.ZkRegistryConfig `yaml:"zk_registry_config" json:"zk_registry_config,omitempty"` + Service_List []registry.DefaultServiceConfig `yaml:"service_list" json:"service_list,omitempty"` + Server_List []server.ServerConfig `yaml:"server_list" json:"server_list,omitempty"` } ) diff --git a/jsonrpc/http.go b/jsonrpc/http.go index aa98dc43665f13e7d1b3b36ff32f48b69194856a..131f3c1887f8b3444dd6e6a44807eb309f6bb6aa 100644 --- a/jsonrpc/http.go +++ b/jsonrpc/http.go @@ -39,8 +39,8 @@ type Request struct { contentType string } -func (r *Request) ServiceConfig() registry.ServiceConfigIf { - return ®istry.ServiceConfig{ +func (r *Request) ServiceConfig() registry.ServiceConfig { + return ®istry.DefaultServiceConfig{ Protocol: r.protocol, Service: r.service, Group: r.group, @@ -86,7 +86,7 @@ func NewHTTPClient(opt *HTTPOptions) *HTTPClient { } } -func (c *HTTPClient) NewRequest(conf registry.ServiceConfig, method string, args interface{}) Request { +func (c *HTTPClient) NewRequest(conf registry.DefaultServiceConfig, method string, args interface{}) Request { return Request{ ID: atomic.AddInt64(&c.ID, 1), group: conf.Group, diff --git a/jsonrpc/server.go b/jsonrpc/server.go index 2540a0eed336a16077973dd6b06bee9c6b158f91..1ae3bde05a325fad63a215fd5de70d53c48a9e88 100644 --- a/jsonrpc/server.go +++ b/jsonrpc/server.go @@ -60,7 +60,7 @@ type Option func(*Options) type Options struct { Registry registry.Registry ConfList []server.ServerConfig - ServiceConfList []registry.ServiceConfig + ServiceConfList []registry.DefaultServiceConfig Timeout time.Duration } @@ -95,7 +95,7 @@ func ConfList(confList []server.ServerConfig) Option { } } -func ServiceConfList(confList []registry.ServiceConfig) Option { +func ServiceConfList(confList []registry.DefaultServiceConfig) Option { return func(o *Options) { o.ServiceConfList = confList } diff --git a/registry/registry.go b/registry/registry.go index 1e90b54c272e88bb56189f92fb51c1fc8cfb3522..acc5965eb416caf274023ae43ea6b49ae864b4fb 100644 --- a/registry/registry.go +++ b/registry/registry.go @@ -9,13 +9,13 @@ type Registry interface { //used for service provider calling , register services to registry //And it is also used for service consumer calling , register services cared about ,for dubbo's admin monitoring. - Register(ServiceConfigIf) error + Register(ServiceConfig) error //used for service consumer ,start subscribe service event from registry Subscribe() (Listener, error) //input the serviceConfig , registry should return serviceUrlArray with multi location(provider nodes) available - GetService(ServiceConfig) ([]*ServiceURL, error) + GetService(DefaultServiceConfig) ([]*ServiceURL, error) //close the registry for Elegant closing Close() //return if the registry is closed for consumer subscribing diff --git a/registry/service.go b/registry/service.go index 0d5749daad6eed7ca62171a6292bcceab5827a8c..083b46d56f649c95e671b611e6675141d7b45c29 100644 --- a/registry/service.go +++ b/registry/service.go @@ -17,28 +17,28 @@ import ( // service config ////////////////////////////////////////////// -type ServiceConfigIf interface { +type ServiceConfig interface { Key() string String() string ServiceEqual(url *ServiceURL) bool } -type ServiceConfig struct { +type DefaultServiceConfig struct { Protocol string `required:"true",default:"dubbo" yaml:"protocol" json:"protocol,omitempty"` Service string `required:"true" yaml:"service" json:"service,omitempty"` Group string `yaml:"group" json:"group,omitempty"` Version string `yaml:"version" json:"version,omitempty"` } -func (c ServiceConfig) Key() string { +func (c DefaultServiceConfig) Key() string { return fmt.Sprintf("%s@%s", c.Service, c.Protocol) } -func (c ServiceConfig) String() string { +func (c DefaultServiceConfig) String() string { return fmt.Sprintf("%s@%s-%s-%s", c.Service, c.Protocol, c.Group, c.Version) } -func (c ServiceConfig) ServiceEqual(url *ServiceURL) bool { +func (c DefaultServiceConfig) ServiceEqual(url *ServiceURL) bool { if c.Protocol != url.Protocol { return false } @@ -59,7 +59,7 @@ func (c ServiceConfig) ServiceEqual(url *ServiceURL) bool { } type ProviderServiceConfig struct { - ServiceConfig + DefaultServiceConfig Path string `yaml:"path" json:"path,omitempty"` Methods string `yaml:"methods" json:"methods,omitempty"` } @@ -139,9 +139,9 @@ func (s ServiceURL) String() string { s.Timeout, s.Version, s.Group, s.Weight, s.Query) } -func (s *ServiceURL) ServiceConfig() ServiceConfig { +func (s *ServiceURL) ServiceConfig() DefaultServiceConfig { interfaceName := s.Query.Get("interface") - return ServiceConfig{ + return DefaultServiceConfig{ Protocol: s.Protocol, Service: interfaceName, Group: s.Group, diff --git a/registry/zookeeper/consumer.go b/registry/zookeeper/consumer.go index a17dd382fe0722a1ffb74a8c43dead6c8eb1503d..b950a74d437e17b1ae1665f7d5a0461d9e6c405e 100644 --- a/registry/zookeeper/consumer.go +++ b/registry/zookeeper/consumer.go @@ -14,7 +14,7 @@ import ( ) // name: service@protocol -func (r *ZkRegistry) GetService(conf registry.ServiceConfig) ([]*registry.ServiceURL, error) { +func (r *ZkRegistry) GetService(conf registry.DefaultServiceConfig) ([]*registry.ServiceURL, error) { var ( ok bool err error @@ -22,8 +22,8 @@ func (r *ZkRegistry) GetService(conf registry.ServiceConfig) ([]*registry.Servic nodes []string listener *zkEventListener serviceURL *registry.ServiceURL - serviceConfIf registry.ServiceConfigIf - serviceConf registry.ServiceConfig + serviceConfIf registry.ServiceConfig + serviceConf registry.DefaultServiceConfig ) r.listenerLock.Lock() listener = r.listener @@ -39,7 +39,7 @@ func (r *ZkRegistry) GetService(conf registry.ServiceConfig) ([]*registry.Servic if !ok { return nil, jerrors.Errorf("Service{%s} has not been registered", conf.Key()) } - serviceConf, ok = serviceConfIf.(registry.ServiceConfig) + serviceConf, ok = serviceConfIf.(registry.DefaultServiceConfig) if !ok { return nil, jerrors.Errorf("Service{%s}: failed to get serviceConfigIf type", conf.Key()) } @@ -93,7 +93,7 @@ func (r *ZkRegistry) getListener() (*zkEventListener, error) { var ( ok bool zkListener *zkEventListener - serviceConf registry.ServiceConfig + serviceConf registry.DefaultServiceConfig ) r.listenerLock.Lock() @@ -120,7 +120,7 @@ func (r *ZkRegistry) getListener() (*zkEventListener, error) { // listen r.cltLock.Lock() for _, svs := range r.services { - if serviceConf, ok = svs.(registry.ServiceConfig); ok { + if serviceConf, ok = svs.(registry.DefaultServiceConfig); ok { go zkListener.listenServiceEvent(serviceConf) } } diff --git a/registry/zookeeper/listener.go b/registry/zookeeper/listener.go index cb3b150e0e3b06912ddbf42b258caf2d1e8c75f8..f9f698cc94477dbadacdf21471de7e416aceeef1 100644 --- a/registry/zookeeper/listener.go +++ b/registry/zookeeper/listener.go @@ -82,7 +82,7 @@ func (l *zkEventListener) listenServiceNodeEvent(zkPath string) bool { return false } -func (l *zkEventListener) handleZkNodeEvent(zkPath string, children []string, conf registry.ServiceConfig) { +func (l *zkEventListener) handleZkNodeEvent(zkPath string, children []string, conf registry.DefaultServiceConfig) { contains := func(s []string, e string) bool { for _, a := range s { if a == e { @@ -156,7 +156,7 @@ func (l *zkEventListener) handleZkNodeEvent(zkPath string, children []string, co } } -func (l *zkEventListener) listenDirEvent(zkPath string, conf registry.ServiceConfig) { +func (l *zkEventListener) listenDirEvent(zkPath string, conf registry.DefaultServiceConfig) { l.wg.Add(1) defer l.wg.Done() @@ -222,7 +222,7 @@ func (l *zkEventListener) listenDirEvent(zkPath string, conf registry.ServiceCon // registry.go:Listen -> listenServiceEvent -> listenDirEvent -> listenServiceNodeEvent // | // --------> listenServiceNodeEvent -func (l *zkEventListener) listenServiceEvent(conf registry.ServiceConfig) { +func (l *zkEventListener) listenServiceEvent(conf registry.DefaultServiceConfig) { var ( err error zkPath string @@ -279,7 +279,7 @@ func (l *zkEventListener) listenServiceEvent(conf registry.ServiceConfig) { } log.Info("listen dubbo path{%s}", zkPath) - go func(zkPath string, conf registry.ServiceConfig) { + go func(zkPath string, conf registry.DefaultServiceConfig) { l.listenDirEvent(zkPath, conf) log.Warn("listenDirEvent(zkPath{%s}) goroutine exit now", zkPath) }(zkPath, conf) diff --git a/registry/zookeeper/registry.go b/registry/zookeeper/registry.go index a05cfa8e8a548b7658b432cff2087f605dfeaa25..62d64c3cbc36f060ca106178ba09b2dd34aeabc6 100644 --- a/registry/zookeeper/registry.go +++ b/registry/zookeeper/registry.go @@ -79,7 +79,7 @@ type ZkRegistry struct { cltLock sync.Mutex client *zookeeperClient - services map[string]registry.ServiceConfigIf // service name + protocol -> service config + services map[string]registry.ServiceConfig // service name + protocol -> service config listenerLock sync.Mutex listener *zkEventListener @@ -97,7 +97,7 @@ func NewZkRegistry(opts ...registry.RegistryOption) (registry.Registry, error) { r = &ZkRegistry{ birth: time.Now().UnixNano(), done: make(chan struct{}), - services: make(map[string]registry.ServiceConfigIf), + services: make(map[string]registry.ServiceConfig), zkPath: make(map[string]int), } @@ -178,8 +178,8 @@ func (r *ZkRegistry) handleZkRestart() { err error flag bool failTimes int - confIf registry.ServiceConfigIf - services []registry.ServiceConfigIf + confIf registry.ServiceConfig + services []registry.ServiceConfig ) defer r.wg.Done() @@ -240,7 +240,7 @@ LOOP: } -func (r *ZkRegistry) Register(regConf registry.ServiceConfigIf) error { +func (r *ZkRegistry) Register(regConf registry.ServiceConfig) error { var ( ok bool err error @@ -249,8 +249,8 @@ func (r *ZkRegistry) Register(regConf registry.ServiceConfigIf) error { switch r.DubboType { case registry.CONSUMER: - var conf registry.ServiceConfig - if conf, ok = regConf.(registry.ServiceConfig); !ok { + var conf registry.DefaultServiceConfig + if conf, ok = regConf.(registry.DefaultServiceConfig); !ok { return jerrors.Errorf("the type of @regConf %T is not registry.ServiceConfig", regConf) } @@ -312,7 +312,7 @@ func (r *ZkRegistry) Register(regConf registry.ServiceConfigIf) error { return nil } -func (r *ZkRegistry) register(c registry.ServiceConfigIf) error { +func (r *ZkRegistry) register(c registry.ServiceConfig) error { var ( err error revision string @@ -365,10 +365,10 @@ func (r *ZkRegistry) register(c registry.ServiceConfigIf) error { return jerrors.Annotatef(err, "zkclient.Create(path:%s)", dubboPath) } params.Add("anyhost", "true") - params.Add("interface", conf.ServiceConfig.Service) + params.Add("interface", conf.DefaultServiceConfig.Service) - if conf.ServiceConfig.Group != "" { - params.Add("group", conf.ServiceConfig.Group) + if conf.DefaultServiceConfig.Group != "" { + params.Add("group", conf.DefaultServiceConfig.Group) } // dubbo java consumer来启动找provider url时,因为category不匹配,会找不到provider,导致consumer启动不了,所以使用consumers&providers // DubboRole = [...]string{"consumer", "", "", "provider"} @@ -378,8 +378,8 @@ func (r *ZkRegistry) register(c registry.ServiceConfigIf) error { params.Add("side", (registry.DubboType(registry.PROVIDER)).Role()) - if conf.ServiceConfig.Version != "" { - params.Add("version", conf.ServiceConfig.Version) + if conf.DefaultServiceConfig.Version != "" { + params.Add("version", conf.DefaultServiceConfig.Version) } if conf.Methods != "" { params.Add("methods", conf.Methods) @@ -402,7 +402,7 @@ func (r *ZkRegistry) register(c registry.ServiceConfigIf) error { log.Debug("provider path:%s, url:%s", dubboPath, rawURL) } else if r.DubboType == registry.CONSUMER { - conf, ok := c.(registry.ServiceConfig) + conf, ok := c.(registry.DefaultServiceConfig) if !ok { return fmt.Errorf("the type of @c:%+v is not registry.ServiceConfig", c) } @@ -446,7 +446,7 @@ func (r *ZkRegistry) register(c registry.ServiceConfigIf) error { dubboPath = fmt.Sprintf("/dubbo/%s/%s", conf.Service, (registry.DubboType(registry.CONSUMER)).String()) log.Debug("consumer path:%s, url:%s", dubboPath, rawURL) } else { - return jerrors.Errorf("@c{%v} type is not ServiceConfig or ProviderServiceConfig", c) + return jerrors.Errorf("@c{%v} type is not DefaultServiceConfig or ProviderServiceConfig", c) } err = r.registerTempZookeeperNode(dubboPath, encodedURL)