diff --git a/config/rpc_service.go b/config/rpc_service.go index 598970505f58992b56e02b841d0bedfb9fef0c75..30c106ea47afa0ff48c483daadf2917d795b5388 100644 --- a/config/rpc_service.go +++ b/config/rpc_service.go @@ -16,7 +16,7 @@ import ( // rpc service interface type RPCService interface { - Service() string // Service Interface + Service() string // Service interfaceName Version() string } diff --git a/config/support/config_loader.go b/config/support/config_loader.go index 48425c2ff9d2586a85b02afbce38eebba9646a09..2de50b9f3d59e3249e990cb8349c55958ab87761 100644 --- a/config/support/config_loader.go +++ b/config/support/config_loader.go @@ -208,18 +208,18 @@ func Load() (map[string]*ReferenceConfig, map[string]*ServiceConfig) { length := len(consumerConfig.References) for index := 0; index < length; index++ { con := &consumerConfig.References[index] - con.Implement(services[con.Interface]) + con.Implement(services[con.interfaceName]) con.Refer() - refMap[con.Interface] = con + refMap[con.interfaceName] = con } // service config length = len(providerConfig.Services) for index := 0; index < length; index++ { pro := &providerConfig.Services[index] - pro.Implement(services[pro.Interface]) + pro.Implement(services[pro.interfaceName]) pro.Export() - srvMap[pro.Interface] = pro + srvMap[pro.interfaceName] = pro } return refMap, srvMap diff --git a/config/support/consumer_config.yml b/config/support/consumer_config.yml index 955e32d199f39985acba55cfbe2837440eb5a1d8..e98c3a4303347c8a5474effdfd2da9c28d5115a1 100644 --- a/config/support/consumer_config.yml +++ b/config/support/consumer_config.yml @@ -26,6 +26,7 @@ registries : address: "127.0.0.1:2181" username: "" password: "" +# default: "true" - id: "shanghaizk" type: "zookeeper" diff --git a/config/support/reference_config.go b/config/support/reference_config.go index 4dc97e0a475c4c525c470089b39bd8c4da50c953..70f1586f3986300bb579270fdb2a1766db6b2897 100644 --- a/config/support/reference_config.go +++ b/config/support/reference_config.go @@ -17,21 +17,22 @@ import ( ) type ReferenceConfig struct { - context context.Context - pxy *proxy.Proxy - Interface string `required:"true" yaml:"interface" json:"interface,omitempty"` - Registries []ConfigRegistry `required:"true" yaml:"registries" json:"registries,omitempty"` - Cluster string `yaml:"cluster" json:"cluster,omitempty"` - Loadbalance string `yaml:"loadbalance" json:"loadbalance,omitempty"` - retries int64 `yaml:"retries" json:"retries,omitempty"` - group string `yaml:"group" json:"group,omitempty"` - version string `yaml:"version" json:"version,omitempty"` - Methods []struct { + context context.Context + pxy *proxy.Proxy + interfaceName string `required:"true" yaml:"interface" json:"interface,omitempty"` + protocol string `yaml:"protocol" json:"protocol,omitempty"` + registries []ConfigRegistry `required:"true" yaml:"registries" json:"registries,omitempty"` + cluster string `yaml:"cluster" json:"cluster,omitempty"` + loadbalance string `yaml:"loadbalance" json:"loadbalance,omitempty"` + retries int64 `yaml:"retries" json:"retries,omitempty"` + group string `yaml:"group" json:"group,omitempty"` + version string `yaml:"version" json:"version,omitempty"` + methods []struct { name string `yaml:"name" json:"name,omitempty"` retries int64 `yaml:"retries" json:"retries,omitempty"` loadbalance string `yaml:"loadbalance" json:"loadbalance,omitempty"` } `yaml:"methods" json:"methods,omitempty"` - Async bool `yaml:"async" json:"async,omitempty"` + async bool `yaml:"async" json:"async,omitempty"` invoker protocol.Invoker } type ConfigRegistry struct { @@ -46,8 +47,8 @@ func (refconfig *ReferenceConfig) Refer() { //棣栧厛鏄痷ser specified SubURL, could be peer-to-peer address, or register center's address. //鍏舵鏄痑ssemble SubURL from register center's configuration妯″紡 - regUrls := loadRegistries(refconfig.Registries, consumerConfig.Registries, config.CONSUMER) - url := config.NewURLWithOptions(refconfig.Interface, config.WithParams(refconfig.getUrlMap())) + regUrls := loadRegistries(refconfig.registries, consumerConfig.Registries, config.CONSUMER) + url := config.NewURLWithOptions(refconfig.interfaceName, config.WithParams(refconfig.getUrlMap())) //set url to regUrls for _, regUrl := range regUrls { @@ -80,13 +81,13 @@ func (refconfig *ReferenceConfig) getUrlMap() url.Values { urlMap := url.Values{} urlMap.Set(constant.TIMESTAMP_KEY, strconv.FormatInt(time.Now().Unix(), 10)) - urlMap.Set(constant.CLUSTER_KEY, refconfig.Cluster) - urlMap.Set(constant.LOADBALANCE_KEY, refconfig.Loadbalance) + urlMap.Set(constant.CLUSTER_KEY, refconfig.cluster) + urlMap.Set(constant.LOADBALANCE_KEY, refconfig.loadbalance) urlMap.Set(constant.RETRIES_KEY, strconv.FormatInt(refconfig.retries, 10)) urlMap.Set(constant.GROUP_KEY, refconfig.group) urlMap.Set(constant.VERSION_KEY, refconfig.version) //getty invoke async or sync - urlMap.Set(constant.ASYNC_KEY, strconv.FormatBool(refconfig.Async)) + urlMap.Set(constant.ASYNC_KEY, strconv.FormatBool(refconfig.async)) //application info urlMap.Set(constant.APPLICATION_KEY, consumerConfig.ApplicationConfig.Name) @@ -97,7 +98,7 @@ func (refconfig *ReferenceConfig) getUrlMap() url.Values { urlMap.Set(constant.OWNER_KEY, consumerConfig.ApplicationConfig.Owner) urlMap.Set(constant.ENVIRONMENT_KEY, consumerConfig.ApplicationConfig.Environment) - for _, v := range refconfig.Methods { + for _, v := range refconfig.methods { urlMap.Set("methods."+v.name+"."+constant.LOADBALANCE_KEY, v.loadbalance) urlMap.Set("methods."+v.name+"."+constant.RETRIES_KEY, strconv.FormatInt(v.retries, 10)) } diff --git a/config/support/registry_config.go b/config/support/registry_config.go index 2b4369a9cbdfb4d9d540e92ac6addb0d1838e54f..6b1bb701d3cbf77f19bb4c562237f5f0083885a0 100644 --- a/config/support/registry_config.go +++ b/config/support/registry_config.go @@ -4,6 +4,7 @@ import ( "context" "github.com/dubbo/dubbo-go/common/constant" "net/url" + "time" ) import ( log "github.com/AlexStocks/log4go" @@ -13,6 +14,7 @@ import "github.com/dubbo/dubbo-go/config" type RegistryConfig struct { Id string `required:"true" yaml:"id" json:"id,omitempty"` TimeoutStr string `yaml:"timeout" default:"5s" json:"timeout,omitempty"` // unit: second + Timeout time.Duration Group string `yaml:"group" json:"group,omitempty"` //for registry Address string `yaml:"address" json:"address,omitempty"` diff --git a/config/support/service_config.go b/config/support/service_config.go index b6c99c92d0dbe3ef563942687c49dc0128b84e0e..e3f42c64ada5f386148e73714a700f8ab159fb4c 100644 --- a/config/support/service_config.go +++ b/config/support/service_config.go @@ -19,15 +19,15 @@ import ( ) type ServiceConfig struct { - context context.Context - Protocol string //multi protocol support, split by ',' - Interface string `required:"true" yaml:"interface" json:"interface,omitempty"` - Registries []ConfigRegistry `required:"true" yaml:"registries" json:"registries,omitempty"` - Cluster string `default:"failover" yaml:"cluster" json:"cluster,omitempty"` - Loadbalance string `default:"random" yaml:"loadbalance" json:"loadbalance,omitempty"` - group string `yaml:"group" json:"group,omitempty"` - version string `yaml:"version" json:"version,omitempty"` - Methods []struct { + context context.Context + protocol string //multi protocol support, split by ',' + interfaceName string `required:"true" yaml:"interface" json:"interface,omitempty"` + registries []ConfigRegistry `required:"true" yaml:"registries" json:"registries,omitempty"` + cluster string `default:"failover" yaml:"cluster" json:"cluster,omitempty"` + loadbalance string `default:"random" yaml:"loadbalance" json:"loadbalance,omitempty"` + group string `yaml:"group" json:"group,omitempty"` + version string `yaml:"version" json:"version,omitempty"` + methods []struct { name string `yaml:"name" json:"name,omitempty"` retries int64 `yaml:"retries" json:"retries,omitempty"` loadbalance string `yaml:"loadbalance" json:"loadbalance,omitempty"` @@ -54,23 +54,23 @@ func (srvconfig *ServiceConfig) Export() error { //TODO:delay export if srvconfig.unexported.Load() { - err := jerrors.Errorf("The service %v has already unexported! ", srvconfig.Interface) + err := jerrors.Errorf("The service %v has already unexported! ", srvconfig.interfaceName) log.Error(err.Error()) return err } if srvconfig.exported.Load() { - log.Warn("The service %v has already exported! ", srvconfig.Interface) + log.Warn("The service %v has already exported! ", srvconfig.interfaceName) return nil } - regUrls := loadRegistries(srvconfig.Registries, providerConfig.Registries, config.PROVIDER) + regUrls := loadRegistries(srvconfig.registries, providerConfig.Registries, config.PROVIDER) urlMap := srvconfig.getUrlMap() - for _, proto := range loadProtocol(srvconfig.Protocol, providerConfig.Protocols) { + for _, proto := range loadProtocol(srvconfig.protocol, providerConfig.Protocols) { //registry the service reflect _, err := config.ServiceMap.Register(proto.name, srvconfig.rpcService) if err != nil { - err := jerrors.Errorf("The service %v export the protocol %v error! Error message is %v .", srvconfig.Interface, proto.name, err.Error()) + err := jerrors.Errorf("The service %v export the protocol %v error! Error message is %v .", srvconfig.interfaceName, proto.name, err.Error()) log.Error(err.Error()) return err } @@ -78,7 +78,7 @@ func (srvconfig *ServiceConfig) Export() error { if contextPath == "" { contextPath = providerConfig.Path } - url := config.NewURLWithOptions(srvconfig.Interface, + url := config.NewURLWithOptions(srvconfig.interfaceName, config.WithProtocol(proto.name), config.WithIp(proto.ip), config.WithPort(proto.port), @@ -104,8 +104,8 @@ func (srvconfig *ServiceConfig) getUrlMap() url.Values { urlMap := url.Values{} urlMap.Set(constant.TIMESTAMP_KEY, strconv.FormatInt(time.Now().Unix(), 10)) - urlMap.Set(constant.CLUSTER_KEY, srvconfig.Cluster) - urlMap.Set(constant.LOADBALANCE_KEY, srvconfig.Loadbalance) + urlMap.Set(constant.CLUSTER_KEY, srvconfig.cluster) + urlMap.Set(constant.LOADBALANCE_KEY, srvconfig.loadbalance) urlMap.Set(constant.WARMUP_KEY, srvconfig.warmup) urlMap.Set(constant.RETRIES_KEY, strconv.FormatInt(srvconfig.retries, 10)) urlMap.Set(constant.GROUP_KEY, srvconfig.group) @@ -119,7 +119,7 @@ func (srvconfig *ServiceConfig) getUrlMap() url.Values { urlMap.Set(constant.OWNER_KEY, providerConfig.ApplicationConfig.Owner) urlMap.Set(constant.ENVIRONMENT_KEY, providerConfig.ApplicationConfig.Environment) - for _, v := range srvconfig.Methods { + for _, v := range srvconfig.methods { urlMap.Set("methods."+v.name+"."+constant.LOADBALANCE_KEY, v.loadbalance) urlMap.Set("methods."+v.name+"."+constant.RETRIES_KEY, strconv.FormatInt(v.retries, 10)) urlMap.Set("methods."+v.name+"."+constant.WEIGHT_KEY, strconv.FormatInt(v.weight, 10)) diff --git a/config/url.go b/config/url.go index ec35f36401639c1b82c6c18dc2490b44985e8c4e..99eecd096e30c6062bcb8aeab7e5896a086664ce 100644 --- a/config/url.go +++ b/config/url.go @@ -189,9 +189,9 @@ func (c URL) URLEqual(url URL) bool { //func (c SubURL) String() string { // return fmt.Sprintf( -// "DefaultServiceURL{Protocol:%s, Location:%s, Path:%s, Ip:%s, Port:%s, "+ +// "DefaultServiceURL{protocol:%s, Location:%s, Path:%s, Ip:%s, Port:%s, "+ // "Timeout:%s, Version:%s, Group:%s, Params:%+v}", -// c.Protocol, c.Location, c.Path, c.Ip, c.Port, +// c.protocol, c.Location, c.Path, c.Ip, c.Port, // c.Timeout, c.Version, c.Group, c.Params) //} diff --git a/protocol/protocol.go b/protocol/protocol.go index 06795330618e40de86466d0901462dbfc50e0641..25e2c13e2d5327e561b6081aee5536195c7d64e5 100644 --- a/protocol/protocol.go +++ b/protocol/protocol.go @@ -12,7 +12,7 @@ import ( "github.com/dubbo/dubbo-go/config" ) -// Extension - Protocol +// Extension - protocol type Protocol interface { Export(invoker Invoker) Exporter Refer(url config.URL) Invoker