diff --git a/client/client_transport.go b/client/client_transport.go index a60faab284aca03e486d1a3b934baaa9e4a8f1e5..cee1a1739cee38149d336f40e6ccfdce17900de4 100644 --- a/client/client_transport.go +++ b/client/client_transport.go @@ -9,8 +9,8 @@ import ( ) type Transport interface { - Call(ctx context.Context, url registry.ServiceURL, request Request, resp interface{}) error - NewRequest(conf registry.ServiceConfig, method string, args interface{}) (Request, error) + Call(ctx context.Context, url config.ConfigURL, request Request, resp interface{}) error + NewRequest(conf registry.ReferenceConfig, method string, args interface{}) (Request, error) } ////////////////////////////////////////////// @@ -18,5 +18,5 @@ type Transport interface { ////////////////////////////////////////////// type Request interface { - ServiceConfig() registry.ServiceConfig + ServiceConfig() registry.ReferenceConfig } diff --git a/client/invoker/invoker.go b/client/invoker/invoker.go index 1cc205d218fd69c13f8e91f3266a6e68bb6df114..2e4a5d48842825213c4d60a2aa48ac28ed1d05d0 100644 --- a/client/invoker/invoker.go +++ b/client/invoker/invoker.go @@ -133,7 +133,7 @@ func (ivk *Invoker) update(res *registry.ServiceEvent) { if ok { svcArr.add(res.Service, ivk.ServiceTTL) } else { - ivk.cacheServiceMap[registryKey] = newServiceArray([]registry.ServiceURL{res.Service}) + ivk.cacheServiceMap[registryKey] = newServiceArray([]config.ConfigURL{res.Service}) } case registry.ServiceDel: if ok { @@ -147,7 +147,7 @@ func (ivk *Invoker) update(res *registry.ServiceEvent) { } } -func (ivk *Invoker) getService(registryConf registry.ServiceConfig) (*ServiceArray, error) { +func (ivk *Invoker) getService(registryConf registry.ReferenceConfig) (*ServiceArray, error) { defer ivk.listenerLock.Unlock() registryKey := registryConf.Key() @@ -197,7 +197,7 @@ func (ivk *Invoker) HttpCall(ctx context.Context, reqId int64, req client.Reques 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.ReferenceConfig, method string, args, reply interface{}, opts ...dubbo.CallOption) error { registryArray, err := ivk.getService(registryConf) if err != nil { diff --git a/client/invoker/service_array.go b/client/invoker/service_array.go index 1f78d722ab0e4d948095857f7cb33736f8d956d4..2bd634cf88ac7f82c7331ed5af4499235398e0b8 100644 --- a/client/invoker/service_array.go +++ b/client/invoker/service_array.go @@ -25,12 +25,12 @@ var ( ) type ServiceArray struct { - arr []registry.ServiceURL + arr []config.ConfigURL birth time.Time idx int64 } -func newServiceArray(arr []registry.ServiceURL) *ServiceArray { +func newServiceArray(arr []config.ConfigURL) *ServiceArray { return &ServiceArray{ arr: arr, birth: time.Now(), @@ -45,7 +45,7 @@ func (s *ServiceArray) GetSize() int64 { return int64(len(s.arr)) } -func (s *ServiceArray) GetService(i int64) registry.ServiceURL { +func (s *ServiceArray) GetService(i int64) config.ConfigURL { return s.arr[i] } @@ -60,12 +60,12 @@ func (s *ServiceArray) String() string { return builder.String() } -func (s *ServiceArray) add(registry registry.ServiceURL, ttl time.Duration) { +func (s *ServiceArray) add(registry config.ConfigURL, ttl time.Duration) { s.arr = append(s.arr, registry) s.birth = time.Now().Add(ttl) } -func (s *ServiceArray) del(registry registry.ServiceURL, ttl time.Duration) { +func (s *ServiceArray) del(registry config.ConfigURL, ttl time.Duration) { for i, svc := range s.arr { if svc.PrimitiveURL() == registry.PrimitiveURL() { s.arr = append(s.arr[:i], s.arr[i+1:]...) diff --git a/client/selector/random.go b/client/selector/random.go index 02f27bafdc55d48d6f63cee26e745b8759e98589..906e2d7b56efcb7963ebf2d2ddc0c2cc39ad5fda 100644 --- a/client/selector/random.go +++ b/client/selector/random.go @@ -16,7 +16,7 @@ func NewRandomSelector() Selector { return &RandomSelector{} } -func (s *RandomSelector) Select(ID int64, array client.ServiceArrayIf) (registry.ServiceURL, error) { +func (s *RandomSelector) Select(ID int64, array client.ServiceArrayIf) (config.ConfigURL, error) { if array.GetSize() == 0 { return nil, ServiceArrayEmpty } diff --git a/client/selector/round_robin.go b/client/selector/round_robin.go index 3a429c63ce9e36d3487f8e388382b269ba1cb83a..449d803fe65fec565cd4b5b2971fdbde3e5240cd 100644 --- a/client/selector/round_robin.go +++ b/client/selector/round_robin.go @@ -15,7 +15,7 @@ func NewRoundRobinSelector() Selector { return &RoundRobinSelector{} } -func (s *RoundRobinSelector) Select(ID int64, array client.ServiceArrayIf) (registry.ServiceURL, error) { +func (s *RoundRobinSelector) Select(ID int64, array client.ServiceArrayIf) (config.ConfigURL, error) { if array.GetSize() == 0 { return nil, ServiceArrayEmpty } diff --git a/client/selector/selector.go b/client/selector/selector.go index 7f077c48b143b05ec71b66ae12a7f2cc1d24e6d0..3f72b2b31737635fae676b1b4ac930f5e3776778 100644 --- a/client/selector/selector.go +++ b/client/selector/selector.go @@ -14,5 +14,5 @@ var ( ) type Selector interface { - Select(ID int64, array client.ServiceArrayIf) (registry.ServiceURL, error) + Select(ID int64, array client.ServiceArrayIf) (config.ConfigURL, error) } diff --git a/client/service_array.go b/client/service_array.go index af1aa9c1474cab3178137611274dabd7d6869626..d6f13e0286bda6483549e3d224f169d1f5b2c58b 100644 --- a/client/service_array.go +++ b/client/service_array.go @@ -5,5 +5,5 @@ import "github.com/dubbo/dubbo-go/registry" type ServiceArrayIf interface { GetIdx() *int64 GetSize() int64 - GetService(i int64) registry.ServiceURL + GetService(i int64) config.ConfigURL } diff --git a/common/extension/config.go b/common/extension/config.go index 210949917b2fd64be0c970f147cb7b01034a8f79..307ea35653b603101f20ba22a945327bd3d4052e 100644 --- a/common/extension/config.go +++ b/common/extension/config.go @@ -5,41 +5,33 @@ import ( ) var ( - serviceConfig map[string]func() config.ServiceConfig - url map[string]func(string) config.URL + url map[string]func(string) (config.ConfigURL,error) ) func init() { // init map - serviceConfig = make(map[string]func() config.ServiceConfig) - url = make(map[string]func(string) config.URL) + url = make(map[string]func(string) (config.ConfigURL,error)) } -func SetServiceConfig(name string, v func() config.ServiceConfig) { - serviceConfig[name] = v -} -func SetURL(name string, v func(string) config.URL) { + +func SetURL(name string, v func(string) config.ConfigURL) { url[name] = v } -func GetServiceConfigExtension(name string) config.ServiceConfig { - if name == "" { - name = "default" - } - return serviceConfig[name]() -} -func GetDefaultServiceConfigExtension() config.ServiceConfig { - return serviceConfig["default"]() -} -func GetURLExtension(name string, urlString string) config.URL { + +func GetURLExtension(name string, urlString string) (config.ConfigURL,error){ if name == "" { name = "default" } return url[name](urlString) } -func GetDefaultURLExtension(urlString string) config.URL { +func GetDefaultURLExtension(urlString string) (config.ConfigURL,error) { return url["default"](urlString) } + +func SetDefaultURLExtension(v func(string) (config.ConfigURL,error)) { + url["default"] = v +} diff --git a/config/config.go b/config/config.go deleted file mode 100644 index e2c4002a257269bf59fb474aa42616837a673ac2..0000000000000000000000000000000000000000 --- a/config/config.go +++ /dev/null @@ -1,24 +0,0 @@ -package config - -// Extension - ServiceConfig -type ServiceConfig interface { - Key() string - String() string - ServiceEqual(url URL) bool - // your service config implements must contain properties below - Service() string - Protocol() string - Version() string - Group() string - SetProtocol(string) - SetService(string) - SetVersion(string) - SetGroup(string) - // export - Export() -} - -// Extension - RegisterConfig -type RegisterConfig interface { - IsValid() bool -} diff --git a/config/configloader.go b/config/config_loader.go similarity index 100% rename from config/configloader.go rename to config/config_loader.go diff --git a/config/default/serviceconfig.go b/config/config_url.go similarity index 52% rename from config/default/serviceconfig.go rename to config/config_url.go index 22f26cf964feeac57cf4711ca34382f5b22c77a0..d4e6182c2720979a573030bd8e635f693b6b192c 100644 --- a/config/default/serviceconfig.go +++ b/config/config_url.go @@ -1,7 +1,8 @@ -package _default +package config import ( "fmt" + "github.com/dubbo/dubbo-go/common/extension" "net" "net/url" "strconv" @@ -10,117 +11,54 @@ import ( ) import ( - log "github.com/AlexStocks/log4go" jerrors "github.com/juju/errors" ) -import ( - "github.com/dubbo/dubbo-go/common/extension" - "github.com/dubbo/dubbo-go/config" -) - -func init() { - extension.SetServiceConfig("default", GetServiceConfig) - extension.SetURL("default", GetURL) -} - -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 NewDefaultServiceConfig() DefaultServiceConfig { - return DefaultServiceConfig{} -} - -func (c *DefaultServiceConfig) Key() string { - return fmt.Sprintf("%s@%s", c.Service_, c.Protocol_) -} - -func (c *DefaultServiceConfig) String() string { - return fmt.Sprintf("%s@%s-%s-%s", c.Service_, c.Protocol_, c.Group_, c.Version_) -} - -func (c *DefaultServiceConfig) ServiceEqual(url config.URL) bool { - if c.Protocol_ != url.Protocol() { - return false - } - - if c.Service_ != url.Query().Get("interface") { - return false - } - - if c.Group_ != url.Group() { - return false - } - - if c.Version_ != url.Version() { - return false - } - - return true -} - -func (c *DefaultServiceConfig) Service() string { - return c.Service_ +func init(){ + extension.SetDefaultURLExtension(NewDefaultServiceURL) } -func (c *DefaultServiceConfig) Protocol() string { - return c.Protocol_ -} - -func (c *DefaultServiceConfig) Version() string { - return c.Version_ -} -func (c *DefaultServiceConfig) Group() string { - return c.Group_ -} -func (c *DefaultServiceConfig) SetProtocol(s string) { - c.Protocol_ = s -} -func (c *DefaultServiceConfig) SetService(s string) { - c.Service_ = s -} -func (c *DefaultServiceConfig) SetVersion(s string) { - c.Version_ = s -} +////////////////////////////////////////// +// service url +////////////////////////////////////////// -func (c *DefaultServiceConfig) SetGroup(s string) { - c.Group_ = s +type ConfigURL interface { + Key() string + String() string + ConfigURLEqual(url ConfigURL) bool + PrimitiveURL() string + Query() url.Values + Location() string + Timeout() time.Duration + Group() string + Protocol() string + Version() string + Ip() string + Port() string + Path() string + Service()string + Methods()string } -func (c *DefaultServiceConfig) Export() { - //todo:export -} - -func GetServiceConfig() config.ServiceConfig { - s := NewDefaultServiceConfig() - return &s -} - -///////////////////////////////////// -// url -///////////////////////////////////// - type DefaultServiceURL struct { - Protocol_ string + Service_ string + Protocol_ string `required:"true",default:"dubbo" yaml:"protocol" json:"protocol,omitempty"` Location_ string // ip+port - Path_ string // like /com.ikurento.dubbo.UserProvider3 + Path_ string `yaml:"path" json:"path,omitempty"`// like /com.ikurento.dubbo.UserProvider3 Ip_ string Port_ string Timeout_ time.Duration - Version_ string - Group_ string + Version_ string `yaml:"version" json:"version,omitempty"` + Group_ string `yaml:"group" json:"group,omitempty"` Query_ url.Values Weight_ int32 PrimitiveURL_ string + Methods_ string `yaml:"methods" json:"methods,omitempty"` } -func NewDefaultServiceURL(urlString string) (config.URL, error) { +func NewDefaultServiceURL(urlString string) (ConfigURL, error) { var ( err error rawUrlString string @@ -169,6 +107,19 @@ func NewDefaultServiceURL(urlString string) (config.URL, error) { return s, nil } + + +func (c *DefaultServiceURL) Key() string { + return fmt.Sprintf("%s@%s-%s-%s-%s-%s", c.Service_, c.Protocol_,c.Group_,c.Location_,c.Version_,c.Methods_) +} + + +func (c *DefaultServiceURL) ConfigURLEqual(url ConfigURL) bool { + if c.Key() != url.Key() { + return false + } + return true +} func (s DefaultServiceURL) String() string { return fmt.Sprintf( "DefaultServiceURL{Protocol:%s, Location:%s, Path:%s, Ip:%s, Port:%s, "+ @@ -177,21 +128,9 @@ func (s DefaultServiceURL) String() string { s.Timeout_, s.Version_, s.Group_, s.Weight_, s.Query_) } -func (s *DefaultServiceURL) CheckMethod(method string) bool { - var ( - methodArray []string - ) - - methodArray = strings.Split(s.Query_.Get("methods"), ",") - for _, m := range methodArray { - if m == method { - return true - } - } - - return false +func (s *DefaultServiceURL) Service() string { + return s.Service_ } - func (s *DefaultServiceURL) PrimitiveURL() string { return s.PrimitiveURL_ } @@ -231,10 +170,6 @@ func (s *DefaultServiceURL) Path() string { return s.Path_ } -func GetURL(urlString string) config.URL { - url, err := NewDefaultServiceURL(urlString) - if err != nil { - log.Error(jerrors.Trace(err)) - } - return url +func (c *DefaultServiceURL) Methods() string { + return c.Methods_ } diff --git a/config/reference_config.go b/config/reference_config.go new file mode 100644 index 0000000000000000000000000000000000000000..ca0a54778ab8d0ba79fd9ae12571093859dcd0b4 --- /dev/null +++ b/config/reference_config.go @@ -0,0 +1,10 @@ +package config + +type ReferenceConfig struct { + Service string `required:"true" yaml:"service" json:"service,omitempty"` + URLs []ConfigURL +} + +func NewReferenceConfig() *ReferenceConfig { + return &ReferenceConfig{} +} \ No newline at end of file diff --git a/config/service_config.go b/config/service_config.go new file mode 100644 index 0000000000000000000000000000000000000000..4914eb0677463632fe02a36593b1e9d1a719bc9f --- /dev/null +++ b/config/service_config.go @@ -0,0 +1,11 @@ +package config + + +type ServiceConfig struct { + Service string `required:"true" yaml:"service" json:"service,omitempty"` + URLs []ConfigURL +} + +func NewDefaultProviderServiceConfig() *ServiceConfig { + return &ServiceConfig{} +} diff --git a/config/url.go b/config/url.go deleted file mode 100644 index 63acf9d0fe8d446129add220a38ebb6ace9c25f2..0000000000000000000000000000000000000000 --- a/config/url.go +++ /dev/null @@ -1,21 +0,0 @@ -package config - -import ( - "net/url" - "time" -) - -// Extension - URL -type URL interface { - CheckMethod(string) bool - PrimitiveURL() string - Query() url.Values - Location() string - Timeout() time.Duration - Group() string - Protocol() string - Version() string - Ip() string - Port() string - Path() string -} diff --git a/dubbo/client.go b/dubbo/client.go index 9ea94e8b393b2133e6f89735efa787dc7de5e983..f47920fc7d787572e06c72186eda688ba60f1d6a 100644 --- a/dubbo/client.go +++ b/dubbo/client.go @@ -104,7 +104,7 @@ func NewClient(conf *ClientConfig) (*Client, error) { } // call one way -func (c *Client) CallOneway(addr string, svcUrl registry.ServiceURL, method string, args interface{}, opts ...CallOption) error { +func (c *Client) CallOneway(addr string, svcUrl config.ConfigURL, method string, args interface{}, opts ...CallOption) error { var copts CallOptions for _, o := range opts { @@ -115,7 +115,7 @@ func (c *Client) CallOneway(addr string, svcUrl registry.ServiceURL, method stri } // if @reply is nil, the transport layer will get the response without notify the invoker. -func (c *Client) Call(addr string, svcUrl registry.ServiceURL, method string, args, reply interface{}, opts ...CallOption) error { +func (c *Client) Call(addr string, svcUrl config.ConfigURL, method string, args, reply interface{}, opts ...CallOption) error { var copts CallOptions for _, o := range opts { @@ -130,7 +130,7 @@ func (c *Client) Call(addr string, svcUrl registry.ServiceURL, method string, ar return jerrors.Trace(c.call(ct, addr, svcUrl, method, args, reply, nil, copts)) } -func (c *Client) AsyncCall(addr string, svcUrl registry.ServiceURL, method string, args interface{}, +func (c *Client) AsyncCall(addr string, svcUrl config.ConfigURL, method string, args interface{}, callback AsyncCallback, reply interface{}, opts ...CallOption) error { var copts CallOptions @@ -141,7 +141,7 @@ func (c *Client) AsyncCall(addr string, svcUrl registry.ServiceURL, method strin return jerrors.Trace(c.call(CT_TwoWay, addr, svcUrl, method, args, reply, callback, copts)) } -func (c *Client) call(ct CallType, addr string, svcUrl registry.ServiceURL, method string, +func (c *Client) call(ct CallType, addr string, svcUrl config.ConfigURL, method string, args, reply interface{}, callback AsyncCallback, opts CallOptions) error { if opts.RequestTimeout == 0 { diff --git a/dubbo/server.go b/dubbo/server.go index 4766dbe2f61fe20343aa6b9175f719f8afd39c30..79cc4d51e0059ffb0ed2a537626d63dabe32edcf 100644 --- a/dubbo/server.go +++ b/dubbo/server.go @@ -24,7 +24,7 @@ type Option func(*Options) type Options struct { Registry registry.Registry ConfList []ServerConfig - ServiceConfList []registry.ServiceConfig + ServiceConfList []registry.ReferenceConfig } func newOptions(opt ...Option) Options { @@ -63,11 +63,11 @@ func ConfList(confList []ServerConfig) Option { } } -func ServiceConfList(confList []registry.ServiceConfig) Option { +func ServiceConfList(confList []registry.ReferenceConfig) Option { return func(o *Options) { o.ServiceConfList = confList if o.ServiceConfList == nil { - o.ServiceConfList = []registry.ServiceConfig{} + o.ServiceConfList = []registry.ReferenceConfig{} } } } diff --git a/examples/client_config.go b/examples/client_config.go index bf871ee7fbc7fb1ace9905d20950fe57ff098a5d..59b312c281d3cc6ac60284785bd1da30261c6f28 100644 --- a/examples/client_config.go +++ b/examples/client_config.go @@ -50,9 +50,9 @@ 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 - ServiceConfigType string `default:"default" yaml:"service_config_type" json:"service_config_type,omitempty"` - ServiceConfigList []registry.ServiceConfig `yaml:"-"` - ServiceConfigMapList []map[string]string `yaml:"service_list" json:"service_list,omitempty"` + ServiceConfigType string `default:"default" yaml:"service_config_type" json:"service_config_type,omitempty"` + ServiceConfigList []registry.ReferenceConfig `yaml:"-"` + ServiceConfigMapList []map[string]string `yaml:"service_list" json:"service_list,omitempty"` } ) diff --git a/examples/dubbo/go-server/app/config.go b/examples/dubbo/go-server/app/config.go index 71d4aa5467402c6c0f8b78489b2c911334c0fa75..cc1422d681ee6f077a4dd41b7581fb7074cf202f 100644 --- a/examples/dubbo/go-server/app/config.go +++ b/examples/dubbo/go-server/app/config.go @@ -47,10 +47,10 @@ type ( Registry string `default:"zookeeper" yaml:"registry" json:"registry,omitempty"` ZkRegistryConfig zookeeper.ZkRegistryConfig `yaml:"zk_registry_config" json:"zk_registry_config,omitempty"` - ServiceConfigType string `default:"default" yaml:"service_config_type" json:"service_config_type,omitempty"` - ServiceConfigList []registry.ServiceConfig `yaml:"-"` - ServiceConfigMapList []map[string]string `yaml:"service_list" json:"service_list,omitempty"` - Server_List []server.ServerConfig `yaml:"server_list" json:"server_list,omitempty"` + ServiceConfigType string `default:"default" yaml:"service_config_type" json:"service_config_type,omitempty"` + ServiceConfigList []registry.ReferenceConfig `yaml:"-"` + ServiceConfigMapList []map[string]string `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 55fee69d3d3bd8a0d2360fae40f9c561d8e6997f..4a1a1271582bf43f8ba3c17bd8d0c6632c4e9123 100644 --- a/jsonrpc/http.go +++ b/jsonrpc/http.go @@ -38,10 +38,10 @@ type Request struct { method string args interface{} contentType string - conf registry.ServiceConfig + conf registry.ReferenceConfig } -func (r *Request) ServiceConfig() registry.ServiceConfig { +func (r *Request) ServiceConfig() registry.ReferenceConfig { return r.conf } @@ -83,7 +83,7 @@ func NewHTTPClient(opt *HTTPOptions) *HTTPClient { } } -func (c *HTTPClient) NewRequest(conf registry.ServiceConfig, method string, args interface{}) (client.Request, error) { +func (c *HTTPClient) NewRequest(conf registry.ReferenceConfig, method string, args interface{}) (client.Request, error) { return &Request{ ID: atomic.AddInt64(&c.ID, 1), @@ -97,7 +97,7 @@ func (c *HTTPClient) NewRequest(conf registry.ServiceConfig, method string, args }, nil } -func (c *HTTPClient) Call(ctx context.Context, service registry.ServiceURL, request client.Request, rsp interface{}) error { +func (c *HTTPClient) Call(ctx context.Context, service config.ConfigURL, request client.Request, rsp interface{}) error { // header req := request.(*Request) httpHeader := http.Header{} diff --git a/plugins/plugins.go b/plugins/plugins.go index 9648420d74d931ac51afe636f40eb6caf497b0cc..a7ac0fb7ec068ab5a9550bf294cedccfb023aa2c 100644 --- a/plugins/plugins.go +++ b/plugins/plugins.go @@ -14,19 +14,19 @@ var PluggableLoadbalance = map[string]func() selector.Selector{ // service configuration plugins , related to SeviceConfig for consumer paramters / ProviderSeviceConfig for provider parameters / -// TODO:ServiceEven & ServiceURL subscribed by consumer from provider's listener shoud abstract to interface -var PluggableServiceConfig = map[string]func() registry.ServiceConfig{ - "default": registry.NewDefaultServiceConfig, +// TODO:ServiceEven & ConfigURL subscribed by consumer from provider's listener shoud abstract to interface +var PluggableServiceConfig = map[string]func() registry.ReferenceConfig{ + "default": registry.NewServiceConfig, } var PluggableProviderServiceConfig = map[string]func() registry.ProviderServiceConfig{ "default": registry.NewDefaultProviderServiceConfig, } -var PluggableServiceURL = map[string]func(string) (registry.ServiceURL, error){ +var PluggableServiceURL = map[string]func(string) (config.ConfigURL, error){ "default": registry.NewDefaultServiceURL, } -var defaultServiceConfig = registry.NewDefaultServiceConfig +var defaultServiceConfig = registry.NewServiceConfig var defaultProviderServiceConfig = registry.NewDefaultProviderServiceConfig var defaultServiceURL = registry.NewDefaultServiceURL @@ -34,7 +34,7 @@ var defaultServiceURL = registry.NewDefaultServiceURL func SetDefaultServiceConfig(s string) { defaultServiceConfig = PluggableServiceConfig[s] } -func DefaultServiceConfig() func() registry.ServiceConfig { +func DefaultServiceConfig() func() registry.ReferenceConfig { return defaultServiceConfig } @@ -48,6 +48,6 @@ func DefaultProviderServiceConfig() func() registry.ProviderServiceConfig { func SetDefaultServiceURL(s string) { defaultServiceURL = PluggableServiceURL[s] } -func DefaultServiceURL() func(string) (registry.ServiceURL, error) { +func DefaultServiceURL() func(string) (config.ConfigURL, error) { return defaultServiceURL } diff --git a/registry/event.go b/registry/event.go index 13bb4f73fd0e3870706523e2e7a44360fbc7aa22..63e1a2634a5c569ee7844d4da255768134f84981 100644 --- a/registry/event.go +++ b/registry/event.go @@ -2,6 +2,7 @@ package registry import ( "fmt" + "github.com/dubbo/dubbo-go/config" "math/rand" "time" ) @@ -36,7 +37,7 @@ func (t ServiceEventType) String() string { type ServiceEvent struct { Action ServiceEventType - Service ServiceURL + Service config.ConfigURL } func (e ServiceEvent) String() string { diff --git a/registry/protocol.go b/registry/protocol.go new file mode 100644 index 0000000000000000000000000000000000000000..937962cb1c0fc1f5ab20b5d55954d230490d40d9 --- /dev/null +++ b/registry/protocol.go @@ -0,0 +1,16 @@ +package registry + +type RegistryProtocol struct { +} + +func (*RegistryProtocol)Refer(){ + +} + +func (*RegistryProtocol)Export(){ + +} + +func (*RegistryProtocol)Destroy(){ + +} \ No newline at end of file diff --git a/registry/registry.go b/registry/registry.go index 7ebe55559beb4f81f2ace4c0086978f20d323a44..2ca678a9b9d5a072d1835d994686215b393f84dc 100644 --- a/registry/registry.go +++ b/registry/registry.go @@ -1,17 +1,19 @@ package registry +import "github.com/dubbo/dubbo-go/config" + // Extension - Registry 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(ServiceConfig) error + Register(config.ConfigURL) error //used for service consumer ,start subscribe service event from registry - Subscribe() (Listener, error) + Subscribe(config.ConfigURL) (Listener, error) //input the serviceConfig , registry should return serviceUrlArray with multi location(provider nodes) available - GetService(ServiceConfig) ([]ServiceURL, error) + //GetService(ConfigURL) ([]ConfigURL, 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 deleted file mode 100644 index 7d89796aed1a1bb21ab297b553e75123c9e494cc..0000000000000000000000000000000000000000 --- a/registry/service.go +++ /dev/null @@ -1,293 +0,0 @@ -package registry - -import ( - "fmt" - "net" - "net/url" - "strconv" - "strings" - "time" -) - -import ( - jerrors "github.com/juju/errors" -) - -////////////////////////////////////////////// -// service config -////////////////////////////////////////////// - -type ServiceConfig interface { - Key() string - String() string - ServiceEqual(url ServiceURL) bool - //your service config implements must contain properties below - Service() string - Protocol() string - Version() string - Group() string - SetProtocol(string) - SetService(string) - SetVersion(string) - SetGroup(string) -} - -type ProviderServiceConfig interface { - //your service config implements must contain properties below - ServiceConfig - Methods() string - Path() string - SetMethods(string) - SetPath(string) -} - -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 NewDefaultServiceConfig() ServiceConfig { - return &DefaultServiceConfig{} -} - -func (c *DefaultServiceConfig) Key() string { - return fmt.Sprintf("%s@%s", c.Service_, c.Protocol_) -} - -func (c *DefaultServiceConfig) String() string { - return fmt.Sprintf("%s@%s-%s-%s", c.Service_, c.Protocol_, c.Group_, c.Version_) -} - -func (c *DefaultServiceConfig) ServiceEqual(url ServiceURL) bool { - if c.Protocol_ != url.Protocol() { - return false - } - - if c.Service_ != url.Query().Get("interface") { - return false - } - - if c.Group_ != url.Group() { - return false - } - - if c.Version_ != url.Version() { - return false - } - - return true -} - -func (c *DefaultServiceConfig) Service() string { - return c.Service_ -} - -func (c *DefaultServiceConfig) Protocol() string { - return c.Protocol_ -} - -func (c *DefaultServiceConfig) Version() string { - return c.Version_ -} - -func (c *DefaultServiceConfig) Group() string { - return c.Group_ -} -func (c *DefaultServiceConfig) SetProtocol(s string) { - c.Protocol_ = s -} - -func (c *DefaultServiceConfig) SetService(s string) { - c.Service_ = s -} -func (c *DefaultServiceConfig) SetVersion(s string) { - c.Version_ = s -} - -func (c *DefaultServiceConfig) SetGroup(s string) { - c.Group_ = s -} - -type DefaultProviderServiceConfig struct { - *DefaultServiceConfig - Path_ string `yaml:"path" json:"path,omitempty"` - Methods_ string `yaml:"methods" json:"methods,omitempty"` -} - -func NewDefaultProviderServiceConfig() ProviderServiceConfig { - return &DefaultProviderServiceConfig{ - DefaultServiceConfig: NewDefaultServiceConfig().(*DefaultServiceConfig), - } -} - -func (c *DefaultProviderServiceConfig) Methods() string { - return c.Methods_ -} - -func (c *DefaultProviderServiceConfig) Path() string { - return c.Path_ -} - -func (c *DefaultProviderServiceConfig) SetMethods(s string) { - c.Methods_ = s -} - -func (c *DefaultProviderServiceConfig) SetPath(s string) { - c.Path_ = s -} - -////////////////////////////////////////// -// service url -////////////////////////////////////////// - -type ServiceURL interface { - ServiceConfig() ServiceConfig - CheckMethod(string) bool - PrimitiveURL() string - Query() url.Values - Location() string - Timeout() time.Duration - Group() string - Protocol() string - Version() string - Ip() string - Port() string - Path() string -} - -type DefaultServiceURL struct { - Protocol_ string - Location_ string // ip+port - Path_ string // like /com.ikurento.dubbo.UserProvider3 - Ip_ string - Port_ string - Timeout_ time.Duration - Version_ string - Group_ string - Query_ url.Values - Weight_ int32 - PrimitiveURL_ string -} - -func NewDefaultServiceURL(urlString string) (ServiceURL, error) { - var ( - err error - rawUrlString string - serviceUrl *url.URL - s = &DefaultServiceURL{} - ) - - rawUrlString, err = url.QueryUnescape(urlString) - if err != nil { - return nil, jerrors.Errorf("url.QueryUnescape(%s), error{%v}", urlString, err) - } - - serviceUrl, err = url.Parse(rawUrlString) - if err != nil { - return nil, jerrors.Errorf("url.Parse(url string{%s}), error{%v}", rawUrlString, err) - } - - s.Query_, err = url.ParseQuery(serviceUrl.RawQuery) - if err != nil { - return nil, jerrors.Errorf("url.ParseQuery(raw url string{%s}), error{%v}", serviceUrl.RawQuery, err) - } - - s.PrimitiveURL_ = urlString - s.Protocol_ = serviceUrl.Scheme - s.Location_ = serviceUrl.Host - s.Path_ = serviceUrl.Path - if strings.Contains(s.Location_, ":") { - s.Ip_, s.Port_, err = net.SplitHostPort(s.Location_) - if err != nil { - return nil, jerrors.Errorf("net.SplitHostPort(Url.Host{%s}), error{%v}", s.Location_, err) - } - } - s.Group_ = s.Query_.Get("group") - s.Version_ = s.Query_.Get("version") - timeoutStr := s.Query_.Get("timeout") - if len(timeoutStr) == 0 { - timeoutStr = s.Query_.Get("default.timeout") - } - if len(timeoutStr) != 0 { - timeout, err := strconv.Atoi(timeoutStr) - if err == nil && timeout != 0 { - s.Timeout_ = time.Duration(timeout * 1e6) // timeout unit is millisecond - } - } - - return s, nil -} - -func (s DefaultServiceURL) String() string { - return fmt.Sprintf( - "DefaultServiceURL{Protocol:%s, Location:%s, Path:%s, Ip:%s, Port:%s, "+ - "Timeout:%s, Version:%s, Group:%s, Weight_:%d, Query:%+v}", - s.Protocol_, s.Location_, s.Path_, s.Ip_, s.Port_, - s.Timeout_, s.Version_, s.Group_, s.Weight_, s.Query_) -} - -func (s *DefaultServiceURL) ServiceConfig() ServiceConfig { - interfaceName := s.Query_.Get("interface") - return &DefaultServiceConfig{ - Protocol_: s.Protocol_, - Service_: interfaceName, - Group_: s.Group_, - Version_: s.Version_, - } -} - -func (s *DefaultServiceURL) CheckMethod(method string) bool { - var ( - methodArray []string - ) - - methodArray = strings.Split(s.Query_.Get("methods"), ",") - for _, m := range methodArray { - if m == method { - return true - } - } - - return false -} - -func (s *DefaultServiceURL) PrimitiveURL() string { - return s.PrimitiveURL_ -} - -func (s *DefaultServiceURL) Timeout() time.Duration { - return s.Timeout_ -} -func (s *DefaultServiceURL) Location() string { - return s.Location_ -} - -func (s *DefaultServiceURL) Query() url.Values { - return s.Query_ -} - -func (s *DefaultServiceURL) Group() string { - return s.Group_ -} - -func (s *DefaultServiceURL) Protocol() string { - return s.Protocol_ -} - -func (s *DefaultServiceURL) Version() string { - return s.Version_ -} - -func (s *DefaultServiceURL) Ip() string { - return s.Ip_ -} - -func (s *DefaultServiceURL) Port() string { - return s.Port_ -} - -func (s *DefaultServiceURL) Path() string { - return s.Path_ -} diff --git a/registry/zookeeper/consumer.go b/registry/zookeeper/consumer.go index c1bf9ff32c2244912fc813049ca160ebe83deca0..3dfe14699daf1855e465cdab7634e2c7ebfdd65c 100644 --- a/registry/zookeeper/consumer.go +++ b/registry/zookeeper/consumer.go @@ -1,96 +1,91 @@ package zookeeper import ( - "fmt" -) - -import ( - log "github.com/AlexStocks/log4go" + "github.com/dubbo/dubbo-go/config" jerrors "github.com/juju/errors" ) import ( - "github.com/dubbo/dubbo-go/plugins" "github.com/dubbo/dubbo-go/registry" ) // name: service@protocol -func (r *ZkRegistry) GetService(conf registry.ServiceConfig) ([]registry.ServiceURL, error) { - - var ( - err error - dubboPath string - nodes []string - listener *zkEventListener - serviceURL registry.ServiceURL - serviceConf registry.ServiceConfig - ok bool - ) - r.listenerLock.Lock() - listener = r.listener - r.listenerLock.Unlock() - - if listener != nil { - listener.listenServiceEvent(conf) - } - - r.cltLock.Lock() - serviceConf, ok = r.services[conf.Key()] - r.cltLock.Unlock() - if !ok { - return nil, jerrors.Errorf("Service{%s} has not been registered", conf.Key()) - } - if !ok { - return nil, jerrors.Errorf("Service{%s}: failed to get serviceConfigIf type", conf.Key()) - } - - dubboPath = fmt.Sprintf("/dubbo/%s/providers", conf.Service()) - err = r.validateZookeeperClient() - if err != nil { - return nil, jerrors.Trace(err) - } - r.cltLock.Lock() - nodes, err = r.client.getChildren(dubboPath) - r.cltLock.Unlock() - if err != nil { - log.Warn("getChildren(dubboPath{%s}) = error{%v}", dubboPath, err) - return nil, jerrors.Trace(err) - } - - var listenerServiceMap = make(map[string]registry.ServiceURL) - for _, n := range nodes { - - serviceURL, err = plugins.DefaultServiceURL()(n) - if err != nil { - log.Error("NewDefaultServiceURL({%s}) = error{%v}", n, err) - continue - } - if !serviceConf.ServiceEqual(serviceURL) { - log.Warn("serviceURL{%s} is not compatible with ServiceConfig{%#v}", serviceURL, serviceConf) - continue - } - - _, ok := listenerServiceMap[serviceURL.Query().Get(serviceURL.Location())] - if !ok { - listenerServiceMap[serviceURL.Location()] = serviceURL - continue - } - } - - var services []registry.ServiceURL - for _, service := range listenerServiceMap { - services = append(services, service) - } - - return services, nil -} - -func (r *ZkRegistry) Subscribe() (registry.Listener, error) { +//func (r *ZkRegistry) GetService(conf registry.ReferenceConfig) ([]config.ConfigURL, error) { +// +// var ( +// err error +// dubboPath string +// nodes []string +// listener *zkEventListener +// serviceURL config.ConfigURL +// serviceConf registry.ReferenceConfig +// ok bool +// ) +// r.listenerLock.Lock() +// listener = r.listener +// r.listenerLock.Unlock() +// +// if listener != nil { +// listener.listenServiceEvent(conf) +// } +// +// r.cltLock.Lock() +// serviceConf, ok = r.services[conf.Key()] +// r.cltLock.Unlock() +// if !ok { +// return nil, jerrors.Errorf("Service{%s} has not been registered", conf.Key()) +// } +// if !ok { +// return nil, jerrors.Errorf("Service{%s}: failed to get serviceConfigIf type", conf.Key()) +// } +// +// dubboPath = fmt.Sprintf("/dubbo/%s/providers", conf.Service()) +// err = r.validateZookeeperClient() +// if err != nil { +// return nil, jerrors.Trace(err) +// } +// r.cltLock.Lock() +// nodes, err = r.client.getChildren(dubboPath) +// r.cltLock.Unlock() +// if err != nil { +// log.Warn("getChildren(dubboPath{%s}) = error{%v}", dubboPath, err) +// return nil, jerrors.Trace(err) +// } +// +// var listenerServiceMap = make(map[string]config.ConfigURL) +// for _, n := range nodes { +// +// serviceURL, err = plugins.DefaultServiceURL()(n) +// if err != nil { +// log.Error("NewDefaultServiceURL({%s}) = error{%v}", n, err) +// continue +// } +// if !serviceConf.ServiceEqual(serviceURL) { +// log.Warn("serviceURL{%s} is not compatible with ReferenceConfig{%#v}", serviceURL, serviceConf) +// continue +// } +// +// _, ok := listenerServiceMap[serviceURL.Query().Get(serviceURL.Location())] +// if !ok { +// listenerServiceMap[serviceURL.Location()] = serviceURL +// continue +// } +// } +// +// var services []config.ConfigURL +// for _, service := range listenerServiceMap { +// services = append(services, service) +// } +// +// return services, nil +//} + +func (r *ZkRegistry) Subscribe(conf config.ConfigURL) (registry.Listener, error) { r.wg.Add(1) - return r.getListener() + return r.getListener(conf) } -func (r *ZkRegistry) getListener() (*zkEventListener, error) { +func (r *ZkRegistry) getListener(conf config.ConfigURL) (*zkEventListener, error) { var ( zkListener *zkEventListener ) @@ -119,7 +114,9 @@ func (r *ZkRegistry) getListener() (*zkEventListener, error) { // listen r.cltLock.Lock() for _, svs := range r.services { - go zkListener.listenServiceEvent(svs) + if svs.ConfigURLEqual(conf){ + go zkListener.listenServiceEvent(svs) + } } r.cltLock.Unlock() diff --git a/registry/zookeeper/listener.go b/registry/zookeeper/listener.go index 1c182cae2b1295c98d6d0c1583a0dbdfba1c50d3..26cae97cb8686dead56a392b02f5437e2bbe7c56 100644 --- a/registry/zookeeper/listener.go +++ b/registry/zookeeper/listener.go @@ -2,6 +2,8 @@ package zookeeper import ( "fmt" + "github.com/dubbo/dubbo-go/common/extension" + "github.com/dubbo/dubbo-go/config" "path" "sync" "time" @@ -83,7 +85,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 config.ConfigURL) { contains := func(s []string, e string) bool { for _, a := range s { if a == e { @@ -103,7 +105,7 @@ func (l *zkEventListener) handleZkNodeEvent(zkPath string, children []string, co // a node was added -- listen the new node var ( newNode string - serviceURL registry.ServiceURL + serviceURL config.ConfigURL ) for _, n := range newChildren { if contains(children, n) { @@ -117,14 +119,14 @@ func (l *zkEventListener) handleZkNodeEvent(zkPath string, children []string, co log.Error("NewDefaultServiceURL(%s) = error{%v}", n, jerrors.ErrorStack(err)) continue } - if !conf.ServiceEqual(serviceURL) { - log.Warn("serviceURL{%s} is not compatible with ServiceConfig{%#v}", serviceURL, conf) + if !conf.ConfigURLEqual(serviceURL) { + log.Warn("serviceURL{%s} is not compatible with ConfigURL{%#v}", serviceURL, conf) continue } log.Info("add serviceURL{%s}", serviceURL) l.events <- zkEvent{®istry.ServiceEvent{Action: registry.ServiceAdd, Service: serviceURL}, nil} // listen l service node - go func(node string, serviceURL registry.ServiceURL) { + go func(node string, serviceURL config.ConfigURL) { log.Info("delete zkNode{%s}", node) if l.listenServiceNodeEvent(node) { log.Info("delete serviceURL{%s}", serviceURL) @@ -143,9 +145,9 @@ func (l *zkEventListener) handleZkNodeEvent(zkPath string, children []string, co oldNode = path.Join(zkPath, n) log.Warn("delete zkPath{%s}", oldNode) - serviceURL, err = registry.NewDefaultServiceURL(n) - if !conf.ServiceEqual(serviceURL) { - log.Warn("serviceURL{%s} has been deleted is not compatible with ServiceConfig{%#v}", serviceURL, conf) + serviceURL, err = extension.GetDefaultURLExtension(n) + if !conf.ConfigURLEqual(serviceURL) { + log.Warn("serviceURL{%s} has been deleted is not compatible with ConfigURL{%#v}", serviceURL, conf) continue } log.Warn("delete serviceURL{%s}", serviceURL) @@ -157,7 +159,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 config.ConfigURL) { l.wg.Add(1) defer l.wg.Done() @@ -193,7 +195,7 @@ func (l *zkEventListener) listenDirEvent(zkPath string, conf registry.ServiceCon continue case <-l.client.done(): l.client.unregisterEvent(zkPath, &event) - log.Warn("client.done(), listen(path{%s}, ServiceConfig{%#v}) goroutine exit now...", zkPath, conf) + log.Warn("client.done(), listen(path{%s}, ReferenceConfig{%#v}) goroutine exit now...", zkPath, conf) return case <-event: log.Info("get zk.EventNodeDataChange notify event") @@ -213,7 +215,7 @@ func (l *zkEventListener) listenDirEvent(zkPath string, conf registry.ServiceCon } l.handleZkNodeEvent(zkEvent.Path, children, conf) case <-l.client.done(): - log.Warn("client.done(), listen(path{%s}, ServiceConfig{%#v}) goroutine exit now...", zkPath, conf) + log.Warn("client.done(), listen(path{%s}, ReferenceConfig{%#v}) goroutine exit now...", zkPath, conf) return } } @@ -223,13 +225,13 @@ 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 config.ConfigURL) { var ( err error zkPath string dubboPath string children []string - serviceURL registry.ServiceURL + serviceURL config.ConfigURL ) zkPath = fmt.Sprintf("/dubbo/%s/providers", conf.Service()) @@ -260,8 +262,8 @@ func (l *zkEventListener) listenServiceEvent(conf registry.ServiceConfig) { log.Error("NewDefaultServiceURL(r{%s}) = error{%v}", c, err) continue } - if !conf.ServiceEqual(serviceURL) { - log.Warn("serviceURL{%s} is not compatible with ServiceConfig{%#v}", serviceURL, conf) + if !conf.ConfigURLEqual(serviceURL) { + log.Warn("serviceURL{%s} is not compatible with ConfigURL{%#v}", serviceURL, conf) continue } log.Debug("add serviceUrl{%s}", serviceURL) @@ -270,7 +272,7 @@ func (l *zkEventListener) listenServiceEvent(conf registry.ServiceConfig) { // listen l service node dubboPath = path.Join(zkPath, c) log.Info("listen dubbo service key{%s}", dubboPath) - go func(zkPath string, serviceURL registry.ServiceURL) { + go func(zkPath string, serviceURL config.ConfigURL) { if l.listenServiceNodeEvent(dubboPath) { log.Debug("delete serviceUrl{%s}", serviceURL) l.events <- zkEvent{®istry.ServiceEvent{Action: registry.ServiceDel, Service: serviceURL}, nil} @@ -280,7 +282,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 config.ConfigURL) { 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 fa01b045792934e1fd9f8ead1f66be81312edbb4..1cd534f9ad6e8ec2fcd3e67ed2bd1f7703f205bd 100644 --- a/registry/zookeeper/registry.go +++ b/registry/zookeeper/registry.go @@ -2,6 +2,7 @@ package zookeeper import ( "fmt" + "github.com/dubbo/dubbo-go/config" "github.com/dubbo/dubbo-go/plugins" "net/url" "os" @@ -81,7 +82,7 @@ type ZkRegistry struct { cltLock sync.Mutex client *zookeeperClient - services map[string]registry.ServiceConfig // service name + protocol -> service config + services map[string]config.ConfigURL // service name + protocol -> service config listenerLock sync.Mutex listener *zkEventListener @@ -99,7 +100,7 @@ func NewZkRegistry(opts ...registry.RegistryOption) (registry.Registry, error) { r = &ZkRegistry{ birth: time.Now().UnixNano(), done: make(chan struct{}), - services: make(map[string]registry.ServiceConfig), + services: make(map[string]config.ConfigURL), zkPath: make(map[string]int), } @@ -181,8 +182,8 @@ func (r *ZkRegistry) handleZkRestart() { err error flag bool failTimes int - confIf registry.ServiceConfig - services []registry.ServiceConfig + confIf config.ConfigURL + services []config.ConfigURL ) defer r.wg.Done() @@ -242,7 +243,7 @@ LOOP: } } -func (r *ZkRegistry) Register(conf registry.ServiceConfig) error { +func (r *ZkRegistry) Register(conf config.ConfigURL) error { var ( ok bool err error @@ -302,7 +303,7 @@ func (r *ZkRegistry) Register(conf registry.ServiceConfig) error { return nil } -func (r *ZkRegistry) register(c registry.ServiceConfig) error { +func (r *ZkRegistry) register(c config.ConfigURL) error { var ( err error revision string @@ -311,8 +312,7 @@ func (r *ZkRegistry) register(c registry.ServiceConfig) error { rawURL string encodedURL string dubboPath string - conf registry.ProviderServiceConfig - ok bool + conf config.ConfigURL ) err = r.validateZookeeperClient() @@ -341,9 +341,7 @@ func (r *ZkRegistry) register(c registry.ServiceConfig) error { switch r.DubboType { case registry.PROVIDER: - if conf, ok = c.(registry.ProviderServiceConfig); !ok { - return jerrors.Errorf("conf is not ProviderServiceConfig") - } + if conf.Service() == "" || conf.Methods() == "" { return jerrors.Errorf("conf{Service:%s, Methods:%s}", conf.Service(), conf.Methods()) } @@ -434,7 +432,7 @@ func (r *ZkRegistry) register(c registry.ServiceConfig) error { dubboPath = fmt.Sprintf("/dubbo/%s/%s", c.Service(), (registry.DubboType(registry.CONSUMER)).String()) log.Debug("consumer path:%s, url:%s", dubboPath, rawURL) default: - return jerrors.Errorf("@c{%v} type is not DefaultServiceConfig or DefaultProviderServiceConfig", c) + return jerrors.Errorf("@c{%v} type is not referencer or provider", c) } err = r.registerTempZookeeperNode(dubboPath, encodedURL)